Problem 860
Number of Common Factors
Easy · 10 pts · Math, Number Theory
Problem
Count the positive integers that divide both A and B. Every common factor of A and B divides gcd(A, B), and every divisor of the gcd divides both, so the answer is the number of divisors of gcd(A, B). Count those divisors by checking d from 1 up to the square root of the gcd, counting d and gcd / d when d divides it.
Input
A single line with two integers A and B.
Output
Print the number of common factors.
Constraints
1 <= A, B <= 10^9
Example input
12 6
Example output
4
Explanation
The common factors of 12 and 6 are 1, 2, 3 and 6, so the answer is 4.