import sys, time, random from collections import deque, Counter, defaultdict def debug(*x):print('debug:',*x, file=sys.stderr) input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 61 - 1 mod = 998244353 # fib = [1, 1] # N, M = [random.randint(1, 100) for _ in range(2)] # for i in range(2, M + 100): # fib.append((fib[-1] + fib[-2])) # ans1 = 0 # for l in range(len(fib)): # for r in range(l + 1, len(fib) + 1): # if sum(fib[l:r]) <= fib[M] and sum(fib[l:r]) % N == 0: # ans1 += 1 # ans2 = 0 # A = [] # for l in range(1, len(fib)): # for r in range(l + 1, len(fib)): # if fib[r] - fib[l] <= fib[M]: # A.append((l, r)) # A.sort() # print(N, M) # for l, r in A: # print(l, r) n, m = mi() if m <= 5000: fib = [1, 2] for i in range(2, m + 1000): fib.append((fib[-1] + fib[-2])) ans = 0 for l in range(len(fib)): for r in range(l + 1, len(fib)): if fib[r] - fib[l] <= fib[m - 2] and (fib[r] - fib[l]) % n == 0: ans += 1 print(ans) exit() else: raise Exception fib = [1 % n, 2 % n] s = (1, 2) S = set([s,]) cnt = 1 while True: fib.append((fib[-1] + fib[-2]) % n) s = (fib[-2], fib[-1]) if s in S: fib.pop() break S.add(s) cnt += 1 print(len(S), cnt)