Given two positive integers G and L, could you tell me how many solutions of (x, y, z) there are, satisfying that gcd(x, y, z) = G and lcm(x, y, z) = L?
Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the least common multiple of x, y and z.
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.
Note, gcd(x, y, z) means the greatest common divisor of x, y and z, while lcm(x, y, z) means the least common multiple of x, y and z.
Note 2, (1, 2, 3) and (1, 3, 2) are two different solutions.
InputFirst line comes an integer T (T <= 12), telling the number of test cases.
The next T lines, each contains two positive 32-bit signed integers, G and L.
It’s guaranteed that each answer will fit in a 32-bit signed integer.OutputFor each test case, print one line with the number of solutions satisfying the conditions above.Sample Input
2 6 72 7 33
Sample Output
72 0
yesterday like a long time did not figured out this morning ,, sudden inspiration came.
Solution: First, we must understand that the greatest common divisor and least common multiple of the relationship, such as a * b = gcd (a, b) * lcm (a, b) if the two sides at the same time divided by the square of gcd lcm% gcd == 0 so !, if lcm% gcd = 0, then there should not have relations
second: we let gcd and lcm gcd available at the same time divided by the new gcd and lcm gcd = 1 lcm = lcm / gcd they are x / gcd y / gcd z / gcd gcd and the lcm lcm we can be decomposed / gcd can be a
third: max lcm ^ = P1 (A1, A2, A3) * P2 ^ max (B1, B2, B3) ....
X0 = P1 a1 .... ^
Y0 = p1 ^ b1 ...
Z0 = p1 ^ c1 ...
If you say a1 b1 c1 are not 0, then they will not be the greatest common divisor 1, so they have at least three a is 0, a maximum of two to 0 (0 to 3 does not occur, p1 which must be prime factors of a number only) because it is sequential
(0, a1, C1) add up to less a1 the value of C1 0 - a1 we consider equal to 0 and the situation there in order a1-1 ,, the change to a total of 6 (a1-1) species, as well as (0,0, a1) and (0 , a1, a1) we did not consider a total of 3 + 3 kinds Therefore a total of 6 (a1-1) +6 kinds
#include<iostream> #include<cstdio> using namespace std; const int N=1e6+7; bool p[N]={1,1,0}; int prime[N]; int k=0; void pre(){ k=0; for(int i=2;i<N;i++){ if(p[i]==0){ prime[k++]=i; for(intI = I + J; J <= N; = J + I) { P [I] = . 1 ; } } } } int main () { pre (); int T; CIN >> T; the while (T-- ) { int n-, m; Scanf ( " % D% D " , & n-, & m); IF (!% n-m = 0 ) { // common divisor should be the most common multiple of the coefficients a * b = gcd example * both sides while divided by the square of gcd lcm, gcd = 0% SO lcm the puts ( " 0 " ); Continue ; } int x=m/n; int sum=1; for(int i=0;i<k&&prime[i]<x;i++){ if(x%prime[i]==0){ int ans=0; while(x%prime[i]==0){ ans++; x=x/prime[i]; } sum*=6*ans; } } if(x>1) sum*=6; cout<<sum<<endl; } return 0; }