diff options
-rw-r--r-- | euler504.c | 73 | ||||
-rw-r--r-- | euler62.c | 58 |
2 files changed, 131 insertions, 0 deletions
diff --git a/euler504.c b/euler504.c new file mode 100644 index 0000000..3a7d0da --- /dev/null +++ b/euler504.c @@ -0,0 +1,73 @@ +#include <stdio.h> +#include <string.h> +#include <math.h> + +int inside[101][101]; + +int __inside(int a, int b) +{ + int count = 0; + /* y = -a/b * x + a */ + for (int i = 1; i < b; i++) { + int t = a - (i * a) / b - 1; + if (t > 0) + count += t; + } + return count; +} + +void init() +{ + for (int i = 1; i <= 100; i++) { + for (int j = i; j <= 100; j++) { + inside[i][j] = __inside(i, j); + } + } +} + +int ninside(int a, int b) +{ + if (a <= b) + return inside[a][b]; + else + return inside[b][a]; +} + +int issqr(int x) +{ + int sx = sqrt(x); + if (sx * sx == x) + return 1; + else + return 0; +} + +int main() +{ + int a, b, c, d; + int m; + int nsqr = 0; + init(); + scanf("%d", &m); + for (a = 1; a <= m; a++) { + for (b = 1; b <= m; b++) { + for (c = a; c <= m; c++) { + for (d = b; d <= m; d++) { + int count = ninside(a, b) + ninside(a, d) + + ninside(c, b) + ninside(c, d) + + a + b + c + d - 3; + if (issqr(count)) { + if (a == c && b == d) { + nsqr++; + } else if (a == c || b == d) { + nsqr += 2; + } else { + nsqr += 4; + } + } + } + } + } + } + printf("%d\n", nsqr); +} 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++; + } +} |