Project Euler Problem 92 Solution

Project Euler Problem 92 Solution

Square Digit Chains

by {BetaProjects} | Project Euler & HackerRank

Project Euler Problem 92 Statement

Solution

HackerRank version

HackerRank Project Euler 92: how many starting numbers below $10^K$ will arrive at $89$? As the result can be large, print modulo $(10^9 + 7)$

Python Source Code

M=1000000007;
L=int(input());
C = range(81*L+1)
S={0,1,4,9,16,25,36,49,64,81}
d=lambda n: n>1 and (n==89 or d(sum(int(c)**2 for c in str(n))))
p=[1 if i in S else 0 for i in C]
for _ in range(L-1):
    p=[sum(p[j-s] for s in S if j>=s)%M for j in C]
print(sum(v for i,v in enumerate(p) if i and d(i))%M)	

Last Word