Masala #NPHYG0K37O
Common Divisors of Two Numbers
Given two integer numbers, the task is to find count of all common divisors of given numbers?
Numbers A and B are entered
Print the answer
# | input.txt | output.txt |
---|---|---|
1 |
13 99 |
1 |
2 |
20 36 |
3 |
3 |
3 17 |
1 |
Naive Solution
A simple solution is to first find all divisors of first number and store them in an array or hash. Then find common divisors of second number and store them. Finally print common elements of two stored arrays or hash. The key is that the magnitude of powers of prime factors of a divisor should be equal to the minimum power of two prime factors of a and b.