You are viewing a single comment's thread. Return to all comments →
bool check(int n) { for(int i=2;i<=sqrt(n);i++) if(n%i==0) return 0; return 1; } int main() { vector <int> p; int a[1001]={0}; for(int i=2;i<=1000;i++) { if(a[i]==0){ if(check(i)==1) { p.push_back(i); for(int j=2*i;j<=1000;j=j+i) a[j]=1; } } } vector<int>n(1001); n[0]=1; for(auto &n1 : p) { for(int i=n1;i<=1000;i++) n[i]+=n[i-n1]; } int t; cin >> t; while(t--) { int m; cin >> m; cout << n[m]<<endl; } }
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #77: Prime summations
You are viewing a single comment's thread. Return to all comments →