diff options
author | Iru Cai <mytbk920423@gmail.com> | 2018-06-16 16:59:14 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2018-06-16 17:45:47 +0800 |
commit | 84c0b0d2ddd5b7ef2c9132118485d745aef9d2cf (patch) | |
tree | 2ed7a3a5b8473c129e562244c3ed26d182b77f24 /euler62.c | |
parent | 57db469caa62b1bf9a24f56348370d8138a62b10 (diff) | |
download | project_euler-84c0b0d2ddd5b7ef2c9132118485d745aef9d2cf.tar.xz |
62, 504
Diffstat (limited to 'euler62.c')
-rw-r--r-- | euler62.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/euler62.c b/euler62.c new file mode 100644 index 0000000..71c19bd --- /dev/null +++ b/euler62.c @@ -0,0 +1,58 @@ +#include <stdio.h> + +struct cube +{ + long long minc; + int nc; +}; + +struct cube cubes[10000000]; +int ncubes; + +int isperm(long long x, long long y) +{ + int a[10]; + for (int i = 0; i < 10; i++) + a[i] = 0; + + while (x) { + a[x%10]++; + x /= 10; + } + while (y) { + a[y%10]--; + y /= 10; + } + for (int i = 0; i < 10; i++) { + if (a[i] != 0) + return 0; + } + return 1; +} + +int main() +{ + ncubes = 0; + int i = 0; + while (1) { + long long t = (long long)i*i*i; + int hasperm = 0; + for (int j = 0; j < ncubes; j++) { + if (isperm(cubes[j].minc, t)) { + cubes[j].nc++; + if (cubes[j].nc == 5) { + printf("%lld\n", cubes[j].minc); + return 0; + } + hasperm = 1; + break; + } + } + if (hasperm == 0) { + cubes[ncubes].minc = t; + cubes[ncubes].nc = 1; + ncubes++; + } + i++; + } +} |