Skip to content

Instantly share code, notes, and snippets.

@joffilyfe
Created August 15, 2015 22:08
Show Gist options
  • Save joffilyfe/a1cbf6910f1fb839937c to your computer and use it in GitHub Desktop.
Save joffilyfe/a1cbf6910f1fb839937c to your computer and use it in GitHub Desktop.
quantidade = int(input())
somas = []
def is_prime(numero):
for n in range(2, numero/2):
if numero % n == 0:
return False
return True
def to_array(numero):
numero = str(numero)
array = []
for c in numero:
array.append(int(c))
return array
def sum_pow(array):
soma = 0
for n in array:
soma += pow(n, 2)
return soma
def is_cesarino(numero):
array = to_array(str(numero))
soma = sum_pow(array)
if soma not in somas:
if len(somas) > 0:
if soma == 1:
return True
somas.append(soma)
return is_cesarino(soma)
else:
return False
while True:
try:
for n in range(quantidade):
somas = []
entrada = raw_input()
numeros = entrada.split()
numero = int(numeros[len(numeros)-1])
if ((numero != 1) and is_prime(numero)):
if is_cesarino(numero):
print "%d %d YES" % (n+1, numero)
else:
print "%d %d NO" % (n+1, numero)
else:
print "%d %d NO" % (n+1, numero)
except:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment