Created
April 16, 2011 02:22
-
-
Save shnya/922786 to your computer and use it in GitHub Desktop.
square sum.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ time ./a.out
4917092
./a.out 0.02s user 0.02s system 84% cpu 0.048 total