Future_Present @ 2024-08-07 22:36:10
6,7,8,10T了,各位大佬怎么优化
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,ans=0;
inline ll gcd(ll x,ll y){
ll maxx=max(x,y),minn=min(x,y);
return !minn ? maxx : gcd(minn,maxx%minn);
}
inline ll lcm(ll m,ll n){
return m*(n/gcd(m,n));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>a>>b;
for(ll i=2;i<=10000;i++){
ll j;
if(i>max(a,b)) break;
for(j=2;j<=i;j++){
if(j>max(a,b)) break;
if(gcd(i,j)==a && lcm(i,j)==b){
ans++;
// cout<<i<<" "<<j<<" ";
}
}
}
if(a==b)
cout<<1;
else
cout<<ans*2;
return 0;
}
by boy♂Next♂dooor @ 2024-08-07 23:06:47
使用数学知识:
#include<bits/stdc++.h>
using namespace std;
int x,y,s;
int gcd(int a,int b)
{
if(a%b==0) return b;
else return gcd(b,a%b);
}
int main()
{
cin>>x>>y;
if(y%x){
cout<<0;return 0;
}
int k=y/x;
for(int i=1;i<=k;i++)
{
if(k%i==0&&gcd(i,k/i)==1) s++;
}
cout<<s<<endl;
return 0;
}
by boy♂Next♂dooor @ 2024-08-07 23:07:00
@2023csp
by Future_Present @ 2024-08-08 08:12:28
@boy♂Next♂dooor 感谢,已关