Skip to content

Instantly share code, notes, and snippets.

@shnya
Created April 16, 2011 02:22
Show Gist options
  • Save shnya/922786 to your computer and use it in GitHub Desktop.
Save shnya/922786 to your computer and use it in GitHub Desktop.
square sum.
typedef long long int LLI;
#define SZ(x) int(x.size())
#define FOR(x,y,z) for(int x = y; y < z; x++)
#define REP(x,y) FOR(x,0,y)
int main(int argc, char *argv[]){
vector<bool> v(30000000,false);
FOR(i,1,3000){
LLI n = i * i;
FOR(j,i,3000){
v[n + j*j] = true;
}
}
int j = 0;
REP(i,SZ(v)){
if(v[i]) j++;
if(j == 1000000){
cout << i << endl;
return 0;
}
}
return 0;
}
@shnya
Copy link
Author

shnya commented Apr 16, 2011

$ time ./a.out

4917092
./a.out 0.02s user 0.02s system 84% cpu 0.048 total

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment