11549 - Calculator Conundrum


Difficulty : medium

Solution Description :

Ad hoc cycle finding problem

input n & k

1. if k > max then max = k
2. m = k*k
3. new k = take first n digit from m
repeat the process until the value of new k is not repeated
print the value of max

example:
n= 1 k=6

m=36 k=3
m= 9 k=9
m=81 k=8
m=64 k=6
now break the loop, because the value of k (6) is repeated.
and here max = 9

for cycle finding (check repeated value) you can use c++ stl map