-
Notifications
You must be signed in to change notification settings - Fork 0
/
504.go
54 lines (47 loc) · 860 Bytes
/
504.go
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
package main
import "fmt"
var squares [200 * 100]bool
var precomp [101][101]int
func under(a, b, x, y int) bool {
return a*y < b*(a-x)
}
func square(a, b, c, d int) bool {
i := precomp[a][b] + precomp[b][c] + precomp[c][d] + precomp[d][a]
i += a + b + c + d - 3
return squares[i]
}
func main() {
for i := 0; ; i++ {
square := i * i
if square > 200*100 {
break
}
squares[square] = true
}
for a := 1; a <= 100; a++ {
for b := 1; b <= 100; b++ {
for x := 1; x <= 100; x++ {
for y := 1; y <= 100; y++ {
if under(a, b, x, y) {
precomp[a][b]++
} else {
y = 101
}
}
}
}
}
count := 0
for a := 1; a <= 100; a++ {
for b := 1; b <= 100; b++ {
for c := 1; c <= 100; c++ {
for d := 1; d <= 100; d++ {
if square(a, b, c, d) {
count++
}
}
}
}
}
fmt.Println(count)
}