3-Primes Problem (LiveArchive 7235) by ynu_b
Contest: 3408    RunID: 2162912    Status: Accepted    Date: Sun Apr 16 17:31:18 JST 2017


#include <iostream>
#include <climits>
#include <vector>

using namespace std;
int main()
{
    int prime[1000];
    for(int i=0;i<1000;i++){
    	prime[i]=1;
    }
    prime[0] = 0;// 1 is not prime
    for (int i = 0; i < 1000; i++)
    {
        if (prime[i] == 1)
        {
        	//cout<<"hogehoge"<<endl;
            for (int j = (i + 1); (i + 1) * j <= 1000; j++)
            {
                prime[(i + 1) * j - 1] = 0;
            }
        }
    }
    int count = 0;
    for(int i = 0; i < 1000; i++){
        if(prime[i] == 1){
            count++;
        }
    }
    int number[count], n = 0;
    for(int i = 0; i < 1000; i++){
        if(prime[i] == 1){
            number[n] = i + 1;
            n++;
        }
    }
    int t=0;
    cin>>t;
    vector<int> a(t, 0);
    for(int i=0;i<t;i++){
        cin>>a[i];
    }
    for(int i=0;i<t;i++){
        for(int j = 0; j < count; j++){
            for(int k = 0; k < count; k++){
                for(int l = 0; l < count; l++){
                    if(a[i] == number[j] + number[k] + number[l]){
                        cout << number[j] << " " << number[k] << " " << number[l] << endl;
                        goto LABEL;
                    }
                }
            }
        }
        LABEL:
        continue;
    }
    return 0;
}