-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp092.py
More file actions
46 lines (36 loc) · 879 Bytes
/
p092.py
File metadata and controls
46 lines (36 loc) · 879 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Thu May 16 21:09:44 2013
@author: guillermo
"""
#Para los números menores que 10.000.000
#Valor maximo = 9^2 * 7 = 567
#Necesitamos mirar para todos esos números si acaban en 89
array = [False]*567
def endsin89(n):
while n != 89 and n != 1:
st = str(n)
n = 0
for i in range(0, len(st)):
n = n + int(st[i])**2
if n == 89:
return True
elif n == 1:
return False
res = 0
#Inicializamos array
for i in range(0, len(array)):
if endsin89(i):
array[i] = True
def checkarray(n):
global array
aux = 0
st = str(n)
for i in range(0, len(st)):
aux = aux + int(st[i])**2
return array[aux]
res = 0
for i in range(0, 10000000):
if checkarray(i):
res += 1
print res