mod = int(input()) r = int(input()) if r == 0: print("YES") exit() def f(pp): global mod, r ans = True e1, e2 = 0, 0 rr = r while rr % pp == 0: rr //= pp e1 += 1 while mod % pp == 0: mod //= pp e2 += 1 e, ck = min(e1, e2), r for _ in range(e): ck //= pp ans &= e == e2 or (e & 1) == 0 if pp == 2: v2 = min(3, e2) v22 = 1 << v2 ch = e == e2 for i in range(v22): ch |= (i * i - ck) % v22 == 0 ans &= ch else: ans &= e == e2 or pow(ck, pp >> 1, pp) == 1 return ans pp, ans = 2, True while pp * pp <= mod: if mod % pp == 0: ans &= f(pp) pp += 1 if mod != 1: ans &= f(mod) print("YNEOS"[not ans::2])