-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP92.py
53 lines (45 loc) · 1.03 KB
/
P92.py
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
# -*- coding: utf-8 -*-
import numpy as np
import time
#set_89=set([89])
#set_1=set([1])
#
def digs_square(n):
count=0
while n!=0:
count+=(n%10)**2
n=n//10
# for i in str(n):
# count+=int(i)**2
return count
begin_time=time.time()
chain=set()
end=10**7
step=end//50
domain=np.zeros(end)
domain[0]=1
domain[88]=89
for i in range(end):
if i%step==0:
print("{0}/{1} has finished!".format(i+step,end))
if domain[i]!=0:
continue
else:
nex=i+1
chain.add(nex)
while True:
nex=digs_square(nex)
if domain[nex-1]==1:
for j in chain:
domain[j-1]=1
chain=set()
break
if domain[nex-1]==89:
for j in chain:
domain[j-1]=89
chain=set()
break
chain.add(nex)
end_time=time.time()
print("\nresult: {}\n".format(np.sum(domain==89)))
print("time spend: {}".format(end_time-begin_time))