main (p):+ q =: string p.1 as integer else 269696 debug enable debug print "Sets:" \ central loop: calculate new set of endings for powers of 10 set =: new row size 1 init 0 m =: 1 while m < q && set.Count > 0 set =: new set set mod m find q debug print join set m =*10 rounds += 1 debug print '' \ show result print format "Result for %_;:" q if set.Count < 1 print "NO SOLUTION" return row set sort ascending for x =: row set give values print format '%6;^2 = %16_;', x, x^2 print rounds, "rounds, ", $tally, "square/mod calculations" $tally =: () \ calculate new set of endings mod m from m-1 new set (old) mod (m) find (q): new =: new row mm =: 10 * m qm =: q %% mm for i =: give values old for j =: from 0 upto 9*m step m k =: i + j l =: k^2 %% mm $tally += 1 \ global to count calculations if l = qm new[] =: k return new