http://ybt.ssoier.cn:8088/problem_show.php?pid=1915
【题目描述】
二个正整数x0,y0(2≤x0≤100000,2≤y0≤1000000),求满足下列条件的P,Q的个数。
条件:
1.P,Q是正整数;
2.要求P,Q以x0为最大公约数,以y0为最小公倍数。
试求:满足条件的所有可能的两个正整数的个数。
【输入】
输入x0和y0
【输出】
满足条件的所有可能的两个正整数的个数
【输入样例】
3 60
【输出样例】
4
【提示】
样例说明:此时的P Q分别为:
3 60
15 12
12 15
60 3
#include<bits/stdc++.h>
using namespace std;
int gcd(int x, int y){
if(x == 0)
return y;
return gcd(y%x, x);
}
int main(){
long long x0, y0, t, cnt=0;
cin >> x0 >> y0;
for(long long i=x0; i<=sqrt(x0*y0); i++){
if(i%x0 == 0 && y0%i == 0){
t = (x0*y0)/i;
if(gcd(t, i) == x0){//要确保t和i这两个数的最大公约数是x0
if(i == t)
cnt++;
else
cnt+=2;
}
}
}
cout << cnt;
return 0;
}