import math N,B=map(int,input().split()) if B==1: print(0) exit() if math.gcd(N,B)!=1: print('NaN') exit() print(pow(N,-1,B))