-
-
Save daliborfilus/3028780 to your computer and use it in GitHub Desktop.
euler#31 bruteforce
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
#include <stdio.h> | |
int p1, p2, p5, p10, p20, p50, p100, p200; | |
int main() { | |
printf("Starting...\n"); | |
int n = 200; | |
int combinations = 0; | |
for(p1 = 0; p1 <= n; p1 += 1) { | |
for(p2 = 0; p2 <= n; p2 += 2) { | |
for(p5 = 0; p5 <= n; p5 += 5) { | |
for(p10 = 0; p10 <= n; p10 += 10) { | |
for(p20 = 0; p20 <= n; p20 += 20) { | |
for(p50 = 0; p50 <= n; p50 += 50) { | |
for(p100 = 0; p100 <= n; p100 += 100) { | |
for(p200 = 0; p200 <= n; p200 += 200) { | |
if(p1 + p2 + p5 + p10 + p20 + p50 + p100 + p200 == n) { | |
++combinations; | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
printf("Result: %d\n", combinations); | |
return 0; | |
} | |
// Starting... | |
// Result: 73682 | |
// ./a.out 42.63s user 0.05s system 98% cpu 43.474 total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment