Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Numbers Factory by marcelina.gorzelana
def prime(n):
pr = [0, 0]
for e in range(2, n+1):
pr.append(1)
for i in range(2, n):
if pr[i] == 1:
j = 2 * i
while j < n:
pr[j] = 0
j += i
return pr
primes = prime(100000)
def checkio(num):
res = 0
pr = False
df = True
factors = []
digits = []
if primes[num] == 1:
pr = True
if pr == False:
for i in range(9, 1, -1):
while num % i == 0 and num != 0:
num//= i
factors.append(i)
factors.sort(reverse = True)
t = 1
if num == 1:
for d in factors:
res+= t * d
t*= 10
return res
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(20) == 45, "1st example"
assert checkio(21) == 37, "2nd example"
assert checkio(17) == 0, "3rd example"
assert checkio(33) == 0, "4th example"
assert checkio(3125) == 55555, "5th example"
assert checkio(9973) == 0, "6th example"
assert checkio(6561) == 9999, "7th example"
Nov. 22, 2016