You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.

The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$.

For example, the period of string "ABAABAA" is $3$, the period of "AAAA" is $1$, and the period of "AABBB" is $5$.

Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.


-----Input-----

The first line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of letters 'A' and 'B', respectively.


-----Output-----

Print the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.


-----Examples-----
Input
2 4

Output
4

Input
5 3

Output
5



-----Note-----

All the possible periods for the first example:   $3$ "BBABBA"  $4$ "BBAABB"  $5$ "BBBAAB"  $6$ "AABBBB" 

All the possible periods for the second example:   $3$ "BAABAABA"  $5$ "BAABABAA"  $6$ "BABAAABA"  $7$ "BAABAAAB"  $8$ "AAAAABBB" 

Note that these are not the only possible strings for the given periods.

Source: codeforces | Difficulty: VERY_HARD
Tags: Mathematics

Sorting

Implementation


Solutions:
import math
(a, b) = map(int, input().split())
n = a + b
(ans, l) = (0, 1)
while l <= n:
	g = n // l
	if a < g or b < g:
		l = n // g + 1
		continue
	r = n // g
	a_low = (a + g) // (g + 1)
	a_high = a // g
	b_low = (b + g) // (g + 1)
	b_high = b // g
	if a_low <= a_high and b_low <= b_high:
		ans += max(0, min(r, a_high + b_high) - max(l, a_low + b_low) + 1)
	l = r + 1
print(ans)


(a, b) = list(map(int, input().split()))
(ans, l, n) = (0, 1, a + b)
while l <= n:
	g = n // l
	if a < g or b < g:
		l = n // g + 1
		continue
	r = n // g
	al = (a + g) // (g + 1)
	ah = a // g
	bl = (b + g) // (g + 1)
	bh = b // g
	if al <= ah and bl <= bh:
		ans += max(0, min(r, ah + bh) - max(l, al + bl) + 1)
	l = r + 1
print(ans)


import math
(a, b) = [int(x) for x in input().split()]
cnt = 0
ab = a + b
k = 2
while k <= ab:
	t = ab // k
	aPeriod = a // t
	bPeriod = b // t
	aLeft = (a + t) // (t + 1)
	bLeft = (b + t) // (t + 1)
	arem = a - t * aPeriod
	brem = b - t * bPeriod
	if aPeriod >= arem and bPeriod >= brem:
		validK = aPeriod + bPeriod - aLeft - bLeft + 1
		if (t + 1) * (aLeft + bLeft) == ab:
			validK -= 1
		if validK > 0:
			cnt += validK
	k = ab // t + 1
print(cnt)