-
Notifications
You must be signed in to change notification settings - Fork 0
/
p206.go
54 lines (44 loc) · 879 Bytes
/
p206.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"
"math/big"
"time"
)
func IsValid(x []rune) bool {
for i := 0; i < 9; i++ {
if x[i*2] != rune('1')+rune(i) {
return false
}
}
return true
}
func main() {
start := time.Now()
ansThree := big.NewInt(0)
ansThree.SetString("101010103", 10)
ansSeven := big.NewInt(0)
ansSeven.SetString("101010107", 10)
for {
square := big.NewInt(0)
square.Set(ansThree)
square.Mul(square, ansThree)
if IsValid([]rune(square.String())) {
fmt.Print(ansThree.String())
fmt.Println("0")
break
} else {
ansThree.Add(ansThree, big.NewInt(10))
}
square.Set(ansSeven)
square.Mul(square, ansSeven)
if IsValid([]rune(square.String())) {
fmt.Print(ansSeven.String())
fmt.Println("0")
break
} else {
ansSeven.Add(ansSeven, big.NewInt(10))
}
}
elapsed := time.Since(start)
fmt.Println("Elasped:", elapsed)
}