-
Notifications
You must be signed in to change notification settings - Fork 0
/
37.go
74 lines (64 loc) · 1.29 KB
/
37.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"math"
"fmt"
)
func main() {
for n:=9;n<10;n++ {
num, sum := tryN(math.MaxInt32)
fmt.Println("with ", n, "-digit limit, got ", num, " with sum ", sum)
if num == 11 {
break
}
}
}
func tryN(maxN uint64) (total, sum uint64) {
//maxF := math.Pow10(n)
ls := NewLs()
total = 0
sum = 0
maxF := float64(maxN)
ln := int(math.Log10(maxF)) + 1
rec := make([]bool, ln)
for i,_ := range rec {
rec[i] = false
}
marked := uint64(0)
markStep := uint64(2000000000)
ten := uint64(10)
for i:=uint64(11);i<=maxN;i+=2 {
if i >= marked {
marked += markStep
ls.Mark(marked)
}
if ls.Get(i) { continue }
ln := int(math.Log10(float64(i)))
if ln>1 && !rec[ln-1] {
fmt.Println("strange ", ln)
break }
if ln > 0 {
isOk := true
for tmp := i/ten; tmp > uint64(0); tmp /= ten {
if ls.Get(tmp) {
isOk = false
break
}
}
if isOk {
for base := uint64(math.Pow10(ln)); base >= ten; base /= ten {
if ls.Get(i%base) {
isOk = false
break
}
}
}
rec[ln] = true
if isOk {
total ++
fmt.Println("got one ", i)
sum += i
}
}
}
return total, sum
}