Created
June 23, 2017 07:55
-
-
Save NixImagery/8dc1db4fbee2d33c9330b3ccf9aa6d52 to your computer and use it in GitHub Desktop.
From https://www.hackerrank.com/contests/projecteuler/challenges/euler004/submissions/code/1302145538
This file contains 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
int main(){ | |
int t; | |
cin >> t; | |
vector<long> p; | |
for (int a=100001; a < 900010; a+=100001) | |
for (int b = 0; b < 90091; b+=10010) | |
for (int c = 0; c < 9901; c+=1100) | |
p.push_back(a + b + c); | |
sort(p.begin(), p.end()); | |
p.push_back (0); | |
vector<long> xx; | |
for(int x = 100; x < 1000; ++x){ | |
for (int y = 100; y < x; ++y){ | |
long xy = x * y; | |
if (binary_search(p.begin(),p.end(),xy)) | |
xx.push_back(xy); | |
} | |
} | |
sort(xx.begin(),xx.end()); | |
for(int a0 = 0; a0 < t; a0++){ | |
long n; | |
cin >> n; | |
vector<long>::iterator ans = lower_bound(xx.begin(),xx.end(),n) - 1; | |
cout << *ans << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment