import sys, time, random from collections import deque, Counter, defaultdict input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 B, C = map(int,input().split()) P = [] b = B e = 1 for i in range(2,B): if i*i>b:break while b % i == 0: b //= i P.append(i) e *= (i - 1) while b % i == 0: b //= i e *= i if b>1: P.append(b) e *= (b - 1) n = len(P) u = [pow(i,e-1,B)for i in range(B)] d = B // C b = d * B found = [0] * b answer = 0 for i in range(b): if found[i]:continue q = i // d r = i % d c = 1 for p in P: c *= q % p if c == 0: continue answer +=1 if answer >100: print("100+") exit() for j in range(b): s = j // d t = j % d c = 1 for p in P: c *=s % p found[q % B * d + (u[s] * (q * t + r - t)) % d] |= c print(answer)