liuhuanjun @ 2024-10-02 08:26:52
#include <bits/stdc++.h>
using namespace std;
int x,y,ans;
int gys(int r,int l)
{
int c;
while(r%l!=0)
{
c=r%l;
r=l;
l=c;
}
return l;
}
int main() {
cin>>x>>y;
for(int i=x;i<=y;i++)
{
for(int j=x;j<=y;j++)
{
if(gys(i,j)==x&&i*j/gys(i,j)==y) ans++;
}
}
cout<<ans*2;
return 0;
}
by sunrunjie @ 2024-10-10 14:06:23
@liuhuanjun
太长了,看我的
#include<bits/stdc++.h>
using namespace std;
int n,m,sum=0;
int main(){
cin>>n>>m;
for(int i=n;i<=m;i++){
int p=i,q;
if(m*n%p==0){
q=m*n/p;
if(__gcd(q,p)==n){
sum++;
}
}
}
cout<<sum;
}
多简洁
by hans108 @ 2024-10-10 19:37:50
做法容易超时,看看我的代码,(运用了一些数学知识,首先特判x不整除y的情况,注意若y/x为质数,有2组要讨论一下) 代码:
#include <bits/stdc++.h>
using namespace std;
bool is_prime(int n){
if(n<=1) return false;
for(int i=2;i<=sqrt(n);i++){
if(n%i==0) return false;
}
return true;
}
int main(){
int x,y;
cin>>x>>y;
if(y%x!=0){
cout<<0;
return 0;
}
int a=y/x;
long long ans;
if(is_prime(a)){
cout<<2;
return 0;
}
int t=0;
for(int i=2;i<=a/2;i++){
if(a%i==0&&is_prime(i)){
t++;
}
}
ans=(long long)(pow(2,t));
cout<<ans;
return 0;
}
by liuhuanjun @ 2024-10-11 19:23:44
@hans108 谢谢大犇
by liuhuanjun @ 2024-10-11 19:24:04
@sunrunjie 感谢大佬
by sunrunjie @ 2024-10-12 12:37:49
@liuhuanjun 不用谢