题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4497
思路:x%G==0,y%G==0,z%G==0,所以L%G==0,若L%G!=0则一定无解。
考虑
L/G=(p1^t1)*(p2^t2)*......*(pn^tn)
x'=x/G=(p1^a1)*(p2^a2)*......*(pn^an)
y'=y/G=(p1^b1)*(p2^b2)*......*(pn^bn)
z'=z/G=(p1^c1)*(p2^c2)*.......*(pn^cn)
对于pi一定有max(ai,bi,ci)==ti,min(ai,bi,ci)==0,否则最大公约数pi^min(ai,bi,ci)*g>g 。
则对于每个pi有
0 0 ti 三种 ti ti ti 三种 0 ti 1--(ti-1) (ti-1)*6种,所以共有6*ti种。
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e6+50;
int v[maxn];
vector<int> prime;
void prepare()
{
for(int i=2; i<maxn; i++)
{
if(!v[i])
{
prime.push_back(i);
for(int j=2*i; j<maxn; j+=i) v[j]=1;
}
}
/*for(int i=0;i<prime.size();i++)
cout<<i<<" "<<prime[i]<<endl;*/
}
int main()
{
int t;
prepare();
scanf("%d",&t);
while(t--)
{
int L,G,ans=1,tot;
scanf("%d%d",&G,&L);
if(L%G)
{
printf("0\n");
continue;
}
int tmp=L/G;
for(int i=0; i<prime.size(); i++)
if(tmp%prime[i]==0)
{
tot=0;
while(tmp%prime[i]==0)
{
tot++;
tmp/=prime[i];
}
ans*=6*tot;
}
if(tmp>1)ans*=6*tot;
printf("%d\n",ans);
}
return 0;
}