diff options
| author | Reiner Herrmann <reiner@reiner-h.de> | 2014-08-31 20:21:45 +0200 |
|---|---|---|
| committer | Reiner Herrmann <reiner@reiner-h.de> | 2014-08-31 20:35:09 +0200 |
| commit | 95341b61b030c9e1290f3b326cb7ec584f543aea (patch) | |
| tree | 852386fa04d32eb859bca11c0eff7b5ef9e50f00 /062.c | |
| parent | 571164d977f91925c4c76a292f74f5f93d09ae23 (diff) | |
Diffstat (limited to '062.c')
| -rw-r--r-- | 062.c | 57 |
1 files changed, 57 insertions, 0 deletions
@@ -0,0 +1,57 @@ +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +struct number +{ + char digits[10]; +}; + +const int cubecount = 30000; +struct number* cubedigits; + +int main(void) +{ + int i, j; + + cubedigits = (struct number*) malloc(cubecount*sizeof(struct number)); + memset(cubedigits, 0, cubecount*sizeof(struct number)); + + for(i=1; i<cubecount; i++) + { + unsigned long long c = (unsigned long long)i*i*i; + int smallest = 0; + char count; + + while(c > 0) + { + char digit = c % 10; + cubedigits[i].digits[digit]++; + c /= 10; + } + + // search for permutations (i.e. same digits) + count = 0; + for(j=1; j<i; j++) + { + if(memcmp(cubedigits[i].digits, cubedigits[j].digits, sizeof(struct number)) == 0) + { + if(smallest == 0) + smallest = j; + + count++; + } + } + + if(count == 4) // 4 additional permutations + { + printf("%lli\n", (unsigned long long)smallest*smallest*smallest); + break; + } + } + + free(cubedigits); + + return 0; +} + |
