import math class Solution: def solve(self , n , m ): # write code here step=0 if n==1: n+=1 step+=1 if n>=m: step += n-m n=m while abs(n-m)>abs(n-int(round(math.sqrt(m)))) and m>3: step+=abs(m-pow(int(round(math.sqrt(m))),2))+1 m = int(round(math.sqrt(m))) while n!=m: if n>=m: step += n-m n=m else: if n*n<m: n*=n step+=1 else: if n*n-m>=m-n: step+=m-n n = m else: step+=(n*n-m)+1 n=m return step