Two harbor beacons pulse on fixed cycles: beacon A repeats its light pattern every A seconds, and beacon B repeats every B seconds. The harbor authority wants to schedule a maintenance boat that checks both beacons on a single fixed interval of L seconds, where L must evenly divide both cycle lengths so that every check lands exactly on a cycle boundary for each beacon independently. Count how many distinct positive integers L satisfy this condition.
A single line containing two integers A and B, separated by a space.
Print a single integer: the number of positive integers L such that L divides A evenly and L divides B evenly.
Example 1
Input
12 18
Expected
4
Explanation
gcd(12, 18) = 6, and the positive integers dividing both 12 and 18 are exactly the divisors of 6: 1, 2, 3, 6. That is 4 values, so the answer is 4.
Example 2
Input
7 13
Expected
1
Explanation
7 and 13 are coprime, so gcd(7, 13) = 1. The only positive integer dividing both is 1, so the answer is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →