a,n=map(int,input().split()) S=0 A=1 while A<10000000: A*=a S+=1 print(A) print((a**(n%S))%A)