슈콩

[SWEA] 테네스의 특별한 소수 본문

Algorithms/SWEA

[SWEA] 테네스의 특별한 소수

shukong 2025. 11. 18. 19:40

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWRuoqCKkE0DFAXt

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		boolean[] isPrime = new boolean[1000001];
		isPrime[0] = isPrime[1] = true;
		for(int i=2;i*i<=1000000;i++) {
			for(int j=i*i;j<=1000000;j+=i) {
				if(!isPrime[j]) {
					isPrime[j] = true;
				}
			}
		}
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			st = new StringTokenizer(br.readLine());
			String d = st.nextToken(); 
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			int result = 0;
			for(int i=a;i<=b;i++) {
				if(!isPrime[i] && String.valueOf(i).contains(d)) {
					result++;
				}
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 승률 비교하기  (0) 2025.11.18
[SWEA] 세상의 모든 팰린드롬 2  (0) 2025.11.18
[SWEA] 성공적인 공연 기획  (0) 2025.11.18
[SWEA] 극장 좌석  (0) 2025.11.18
[SWEA] 명진이와 동휘의 숫자 맞추기  (0) 2025.11.18