90分 关于最后一点: 以下是用for循环,TLE的代码:
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b)
{
if(b)
{
return gcd(b,a%b);
}
return a;
}
long long cnt=0;
long long t;
long long x,y;
int main(void)
{
scanf("%lld%lld",&x,&y);
if(y%x)
{
cout<<0;
return 0;
}
t=x*y;
for(long long i=1;i<=t;i++)
{
if(t%i==0)
{
int d=t/i;
if(gcd(i,d)==x)
{
cnt++;
}
}
}
printf("%lld",cnt);
return 0;
}
还有用dfsMLE的代码:
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b)
{
if(b)
{
return gcd(b,a%b);
}
return a;
}
long long cnt=0;
long long t;
long long x,y;
long long d;
void dfs(long long i)
{
if(t%i==0)
{
d=t/i;
if(gcd(i,d)==x)
{
cnt++;
}
}
if(i>t)
{
return;
}
dfs(i+1);
}
int main(void)
{
scanf("%lld%lld",&x,&y);
if(y%x)
{
cout<<0;
return 0;
}
t=x*y;
dfs(1);
printf("%lld",cnt);
return 0;
}