fork download
  1. def f(n,A=[],l=0):l=l or len(`n`)/2;return-(n in A)or-~f(n*n/10**l%100**l,A+[n],l)
  2.  
  3. for n in 24, 82, 123456, 8989, 789987:
  4. print '%6d: %d' % (n, f(n))
Success #stdin #stdout 0.01s 9072KB
stdin
Standard input is empty
stdout
    24: 1
    82: 5
123456: 146
  8989: 68
789987: 226