def prime(n):
p=[]
while n!=1:
for i in range(2,n+1):
while n%i==0:
p.append(i)#;print(p)
n=n/i
return p
while True:
try:
A=list(map(int,input().split()))
#print(A)
x=1;time=[]
for i in range(0,len(A),2):
time.append(A[i])
#print(time)
for j in range(len(time)):
x*=time[j]
#print( prime(x-1))
land=[]
setp=sorted(set(prime(x-1)),reverse = True);land=[]
for element in setp:
land.append(element)
land.append(prime(x-1).count(element))
print(*land,end=" ")
print()
except EOFError:
break