Title Description Description
Enter two positive integer x0,y0 (2<=x0<100000,2<=y0<=1000000) to find the number of p,q that meet the following conditions
Condition: 1.p,q is a positive integer
2. Require p,q to x0 for greatest common divisor, y0 as least common multiple.
Trial: The number of all possible two positive integers that satisfy the condition.
Enter a description input Description
Two positive integers x0,y0
Outputs description Output Description
The number of all possible two positive integers that satisfy the condition
Sample input to sample
3 60
Sample output Sample Outputs
4
Analysis:
P and Q's Greatest common divisor (GCD) is x, least common multiple (LCM) is Y
So P*q=x*y
Set P=x*i,q=x*j,i and J coprime
Then p*q= (x*i) * (x*j) =x*y, then there is i*j=y/x
We can enumerate I, starting with I=1, until i*i>y/x
If I is a factor of y/x
Then j= (y/x)/I
Again to determine whether I and J coprime
Because each of the two numbers in the smaller is I, the larger the number is J,i is the small root (y/x), J is greater than the radical (y/x) so does not repeat the calculation, that count to one time, the answer will accumulate 2.
Code:
#include <iostream>using namespace std;int gcd (int x,int y) { return (X%Y==0?Y:GCD (y,x%y));} int main () { int x,y,ans=0; cin>>x>>y; if (y%x) { cout<<0; return 0; } y=y/x; for (int i=1; i*i<=y; i++) { if (Y%I==0&&GCD (i,y/i) ==1) ans+=2; } Cout<<ans<<endl;}
"codevs1012" greatest common divisor and least common multiple