#P1029. Counting Pairs with Given GCD and LCM
Counting Pairs with Given GCD and LCM
Counting Pairs with Given GCD and LCM
You are given two positive integers \(x_0\) and \(y_0\). Your task is to count the number of pairs of positive integers \(P\) and \(Q\) such that:
- \(\gcd(P, Q) = x_0\).
- \(\operatorname{lcm}(P, Q) = y_0\).
It can be shown that if we set \(P = x_0 \times a\) and \(Q = x_0 \times b\), then the conditions become \(\gcd(a, b) = 1\) and \(a \times b = \frac{y_0}{x_0}\). Note that if \(y_0\) is not divisible by \(x_0\), there exists no solution. Otherwise, let \(n = \frac{y_0}{x_0}\). For every prime factor in the prime factorization of \(n\), its complete power must belong either to \(a\) or to \(b\) (to ensure \(\gcd(a, b) = 1\)). Hence, if \(n\) has \(k\) distinct prime factors then there are exactly \(2^k\) valid pairs \((a, b)\), which yields \(2^k\) pairs \((P, Q)\) for the original problem (note that order matters; if \(a \neq b\) then the pairs \((P, Q)\) and \((Q, P)\) are considered distinct).
Your task is to implement a program that reads the input and outputs the number of valid pairs \((P, Q)\).
inputFormat
The input consists of a single line containing two positive integers \(x_0\) and \(y_0\) separated by a space.
outputFormat
Output a single integer representing the number of valid pairs \((P, Q)\) satisfying the conditions.
sample
3 60
4