-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpb26.go
60 lines (54 loc) · 920 Bytes
/
pb26.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
package main
import (
"fmt"
"math/big"
)
func isPrime(in int) bool {
for i:=2;i*i<=in;i++{
if in%i==0{
return false
}
}
return true
}
func allPrimes(lim int) []int{
primes := []int{}
for i:=1;i<=lim;i++{
if isPrime(i){
primes = append(primes, i)
}
}
return primes
}
func bigPow(x,y int) big.Int{
xbig := big.NewInt(int64(x))
res := big.NewInt(1)
for i:=1;i<=y;i++{
res.Mul(res,xbig)
}
return *res
}
func main(){
lim := 1000
primes := allPrimes(lim)
mx_cyc := 0
mx_len := 0
for _,i := range primes {
j := 1
for j<i{
p := new(big.Int)
*p = bigPow(10,j)
res := new(big.Int)
res.Mod(p,big.NewInt(int64(i)))
if res.Int64() == 1{
if mx_len < j{
mx_len = i
mx_cyc = j
}
break
}
j++
}
}
fmt.Printf("Found: 1/%d yields %d cycles\n", mx_len, mx_cyc)
}