16_lln @ 2024-10-20 11:35:01
#include<bits/stdc++.h>
using namespace std;
int x,y,ans;
int main()
{
cin>>x>>y;
int sum=x*y;
for(int i=2;i*i<=sum;i++){
if(sum%i==0){
int cnt=sum/i;
int minn=min(cnt,i);
int maxn=max(cnt,i);
for(int j=2;j<=sqrt(minn);j++){
if(minn%j==0){
if(minn/j==x){
if(cnt*i==y) ans++;
}
}
}
}
}
cout<<ans;
return 0;
}
by Kolkas @ 2024-10-20 20:43:25
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
return b ? gcd(b, a % b) : a;
}
int main()
{
int a, b; cin >>a >>b;
int ans = 0;
for(int i = a; i <= a * b; i += a)
{
int j = a * b / i;
if(gcd(i, j) == a && i * j == a * b)
{
//cout <<i <<" " <<j <<endl;
ans ++;
}
}
cout <<ans <<endl;
return 0;
}
可以看看我的,你的代码明显是可以优化的,最好是去学一下辗转相除法以及gcd lcm之间的关系
by hzyhdd @ 2024-11-01 22:50:37
@Kolkas 还是三目运算符大佬
by 16_lln @ 2024-11-03 09:33:25
@Kolkas 感谢dalao