-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path34.go
56 lines (50 loc) · 738 Bytes
/
34.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
package main
import (
"fmt"
)
var buf []int
func main() {
n := judgeMax()
fmt.Print("result maxN:", n)
sum := 0
for i:=0;i<n;i++ {
if tryOne(i) > 0 {
sum += i
fmt.Println(" got one ", i)
}
}
fmt.Println("result ", sum)
}
func tryOne(n int) int {
sum := 0
num := 0
for nn:=n;nn>0;nn/=10 {
num ++
sum += buf[nn%10]
}
if num > 1 && n == sum {
return n
} else {
return 0
}
}
func judgeMax() int {
ret := 1
buf = make([]int,10)
base := 1
for i,_ := range buf {
if i == 0 {
buf[i] = 1
} else {
base *= i
buf[i] = base
}
}
power:=ret
pp := buf[9]
for ; power < pp; ret ++ {
power *=10
pp += buf[9]
}
return power
}