슈콩

[SWEA] 새샘이와 세 소수 본문

Algorithms/SWEA

[SWEA] 새샘이와 세 소수

shukong 2025. 11. 20. 19:18

 

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWaJ3q8qV-4DFAUQ

 

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));
		int T = Integer.parseInt(br.readLine());
		boolean[] isPrime = new boolean[1000];
		for(int i=2;i*i<1000;i++) {
			if(isPrime[i]) continue;
			for(int j=i*i;j<1000;j+=i) {
				if(!isPrime[j]) isPrime[j] = true;
			}
		}
		for(int tc=1;tc<=T;tc++) {
			int n = Integer.parseInt(br.readLine());
			int result = 0;
			for(int i=2;i<=n;i++) {
				for(int j=i;j<=n;j++) {
					if(!isPrime[i] && !isPrime[j] && i+j<n) {
						for(int k=j;k<=n;k++) {
							if(i+j+k==n && !isPrime[k]) {
								result++;
								break;
							}
						}
					}
				}
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

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

[SWEA] 과자 분배  (0) 2025.11.20
[SWEA] 집합 비교  (0) 2025.11.20
[SWEA] 삼삼 트리플 게임  (0) 2025.11.19
[SWEA] 세영이의 SEM력 연도  (0) 2025.11.19
[SWEA] 조 만들기  (0) 2025.11.19