-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe86.sq
More file actions
85 lines (72 loc) · 1.67 KB
/
Copy pathe86.sq
File metadata and controls
85 lines (72 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local cuboids = [];
for (local i = 0; i < 2000; ++i) {
cuboids.append(0);
}
function gcd(a, b) {
if (b == 0) {
return a;
} else {
return gcd(b, a%b);
}
}
function coprime(a, b) {
return gcd(a,b) == 1;
}
function EuclidLeg1(m, n) {
return square(m) - square(n);
}
function EuclidLeg2(m, n) {
return 2*m*n;
}
function odd(x) {
return x % 2 == 1;
}
function square(x) {
return x * x;
}
function min(x, y) {
if (x < y) {
return x;
} else {
return y;
}
}
function max(x, y) {
return -min(-x, -y);
}
function countCuboids(l1k, l2k) {
local pydiag = square(l1k) + square(l2k);
if (l1k < 2000) {
for (local i = (l2k/2); i > 0; --i) {
if (l2k-i >= 2000) {
return;
} else {
local d1 = square(l2k-i+l1k) + square(i);
local d2 = square(l1k+i) + square(l2k-i);
if (pydiag <= min(d1, d2)) {
cuboids[max(l2k-i, l1k)] += 1;
}
}
}
}
}
for (local m = 1; m < 60; ++m) {
for (local n = 1; n < m; ++n) {
if (odd(m-n) && coprime(m, n)) {
local leg1 = EuclidLeg1(m, n);
local leg2 = EuclidLeg2(m, n);
for (local k=1; k * min(leg1, leg2) < 2000; ++k) {
countCuboids(leg1 * k, leg2 * k);
countCuboids(leg2 * k, leg1 * k);
}
}
}
}
local count = 0;
for (local i = 0; i < 2000; ++i) {
count += cuboids[i];
if (count > 1000000) {
print(i + "\n");
break
}
}