티스토리 뷰
https://www.acmicpc.net/problem/11502
에라토스테네스의 체로 소수를 미리 구한 후 각각의 수를 세 개의 소수의 합으로 나타낼 수 있는지 확인한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <cstdio> #include <vector> using namespace std; int t,k,n,f,c[1000]; vector<int> p; int main() { for(int i=2;i<1000;i++) { if(c[i]) continue; p.push_back(i); for(int j=2*i;j<1000;j+=i) c[j]=1; } n=p.size(); scanf("%d",&t); while(t--) { scanf("%d",&k); for(int a=0;a<n;a++) { for(int b=a;b<n;b++) { for(int c=b;c<n;c++) { if(p[a]+p[b]+p[c]==k) { f=1; printf("%d %d %d\n",p[a],p[b],p[c]); goto next; } } } } next: if(!f) printf("0\n"); f=0; } return 0; } | cs |
'Algorithm > BOJ' 카테고리의 다른 글
11497 통나무 건너뛰기 (0) | 2018.06.07 |
---|---|
10219 Meats On The Grill (0) | 2018.06.07 |
15654 N과 M (5) (0) | 2018.06.06 |
15649 N과 M (1) (0) | 2018.06.06 |
3067 Coins (0) | 2018.05.19 |