P1029题解
思路
因为两个数的积等于它们最大公约数和它们最小公倍数的积,即:
从
注:
-
可以使用 C++ 自带的函数
__gcd()来求最大公倍数\gcd 。 -
如果
P = Q ,易得P = Q = \gcd(P,Q) = \operatorname{lcm}(P,Q) ,只有一种情况,但是这种情况只有在x_0 = y_0 时会出现,所以特判一下就好了。
solution
#include<bits/stdc++.h>
using namespace std;
int x,y,ans;
int main(){
cin>>x>>y;
if(x==y) ans--;
y*=x;
for(int i=1;i<=sqrt(y);i++){
if(y%i==0&&__gcd(i,y/i)==x) ans+=2;
}
cout<<ans;
return 0;
}