题目见这里:https://www.luogu.org/problem/P1029
codes 1:
#include<bits/stdc++.h>
using namespace std;
int m,n,ans=0;
int main()
{
cin>>n>>m;
for(int i=1;i<=sqrt(m*n);i++)
{
if((n*m)%i==0 && __gcd(i,(n*m)/i)==n) ans++;
}
cout<<ans*2<<endl;
return 0;
}
codes 1之优化:
#include<bits/stdc++.h>
using namespace std;
int m,n,ans=0;
int main()
{
cin>>n>>m;
for(int i=n;i<=sqrt(m*n);i++)//对称性!
{
if((n*m)%i==0 && __gcd(i,(n*m)/i)==n) ans++;
}
cout<<ans*2<<endl;
return 0;
}
codes1——gcd
1 #include<bits/stdc++.h> 2 using namespace std; 3 int gcd(int x,int y){return !y?x:gcd(y,x%y);} //精辟简洁的函数语句 4 int main() 5 { 6 int x,y; 7 scanf("%d%d",&x,&y); 8 printf("%d\n",gcd(x,y)); 9 printf("%d\n",__gcd(x,y)); 10 return 0; 11 }