#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int d,m,t,ans;
int gcd(int a,int b)
{
if(b == 0)
return a;
return gcd(b,a%b);
}
int lcm(int a,int b)
{
return a * b / gcd(a,b);
}
int main()
{
cin>>t;
while(t--)
{
cin>>d>>m;
if(d==0||m==0)
{cout<<0<<endl;continue;}
for(int i=d;i<=m;++i)
if(lcm(i, d*m/i)==m && gcd(i, d*m/i)==d )
ans++;
cout<<ans<<endl;
/* for(int i=1;i<=m;++i)
for(int j=1;j<=m;++j)
if(lcm(i, j)==m && gcd(i, j)==d )
ans++;
cout<<ans<<endl;
*/ }
return 0;
}
【模板】gcd+lcm
最新推荐文章于 2022-02-24 15:32:30 发布