-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproblem133.ahk
60 lines (53 loc) · 915 Bytes
/
problem133.ahk
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
IsPrime(n) {
if (n < 2) {
return false
} else {
x = 2
while (x <= Sqrt(n)) {
if (Mod(n, x) == 0) {
return false
}
x += 1
}
return true
}
}
PowerMod(a, b, n) {
p = 2
x = 1
t := b
while (p * 2 <= b) {
p *= 2
}
while (p > 0) {
if (t >= p) {
x := Mod(x * a, n)
t -= p
}
p //= 2
if (p > 0) {
x := Mod(x * x, n)
}
}
return x
}
IsEventuallyOne(p) {
number := Mod(10, p)
while (not visited%number%) {
visited%number% = 1
number := PowerMod(number, 10, p)
}
return number == 1
}
WillDivideRep(p) {
return IsEventuallyOne(9 * p)
}
sum = 0
p = 2
while (p < 100000) {
if (IsPrime(p) and not WillDivideRep(p)) {
sum += p
}
p += 1
}
MsgBox % sum