Problem:
Score : 400 points

Problem Statement

You are given integers N and M.

Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

N \leq M \leq 10^9

Input

Input is given from Standard Input in the following format:

N M

Output

Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

Sample Input 1

3 14

Sample Output 1

2

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.

Sample Input 2

10 123

Sample Output 2

3

Sample Input 3

100000 1000000000

Sample Output 3

10000

Solution in Fortran (gfortran v4.8.4) (judge verdict: Accepted)

program test
implicit none

integer(8) :: n,m,i,j,k,sosuu(32000)=1,temp,sosuu_list(32000)=0,soinsuu_list(32000)=0,count,rest,ans=1,value
integer(8) :: sosuu_list2(32000),soinsuu_list2(32000),count2,bits(32000)=0
read(*,*) n,m

! まず、Mを素因数分解をする
! 次に、N以上を満たす最小のMの約数を探しYとする
! 答えはM/Y

! 素数判定
sosuu(1)=0
do i=2,32000
	if(sosuu(i) == 0)then
		goto 100
	else
		temp = 2*i
		do while(temp <= 32000)
			sosuu(temp) = 0
			temp = temp + i
		enddo
	endif
	100 continue
enddo

! 素数リスト
count=0
do i=2,32000
	if(sosuu(i) == 1)then
		count = count + 1
		sosuu_list(count) = i
	endif
enddo

! 素因数分解をする
rest = m
do i=1,count
	do while(mod(rest,sosuu_list(i))==0)
		rest = rest/sosuu_list(i)
		soinsuu_list(i) = soinsuu_list(i) + 1
	enddo
enddo

count2=0
do i=1,count
	if(soinsuu_list(i) >= 1)then
		count2 = count2 + 1
		sosuu_list2(count2) = sosuu_list(i)
		soinsuu_list2(count2) = soinsuu_list(i)
	endif
enddo

! 最後に残ったrestが素数かもしれない
if(rest >= 2)then
	count2 = count2 + 1
	sosuu_list2(count2) = rest
	soinsuu_list2(count2) = 1
endif

if(m >= 2) then
do
	value = 1
	do i=1,count2
		value = value * sosuu_list2(i) ** bits(i)
	enddo
		
	if(M/value >= N )then
		ans = max(ans,value)
	endif
	
	bits(1) = bits(1) + 1
	do i=1,count2
		if(bits(i) > soinsuu_list2(i)) then
			if(i == count2)then
				goto 200
			else
				bits(i) = 0
				bits(i+1) = bits(i+1) + 1
			endif
		endif
	enddo
	
enddo
200 continue
endif

write(*,*) ans

end program