您的位置:首页 > 其它

hdu5505

2015-10-24 13:19 295 查看
跟5504差不多。。。比赛的时候以为非常水。。。

其实确实挺水的。。。

比赛的时候不想写1000000的筛。。。

就直接对n分解质因数。。。

后来想了一下极限复杂度是nT。。。

【真是不知道脑子怎么长的   ←_←

写筛吧。。。不知道表会不会超长度。。。

这次我觉得我代码太屎了。。。

。。。随便看看就好。。。

最后。。。有个坑。。。就是m要unsigned long long。。。

#include <iostream>
#include <cstdio>
#include <cstring>

int T,i,j,tot,s,e;
unsigned long long n,m;
int p[80000];
const int MAX=1000100;
bool b[MAX];

int main()
{
i=1; tot=0;
for (;;)
{
i++;
while (i<MAX&&b[i]) i++;
if (i==MAX) break;
p[++tot]=i;
for (j=2;i*j<MAX;j++) b[i*j]=1;
}
scanf("%d",&T);
while(T--)
{
scanf("%I64u%I64u",&n,&m);
if (n==m) { puts("0"); continue; }
if (m%n) { puts("-1"); continue; }
int x=0,f=0;
for (i=1;i<=tot;i++)
{
int tmp=0; s=0; e=0;
while (n%p[i]==0) s++,n/=p[i];
while (m%p[i]==0) e++,m/=p[i];
if (!s&&e) { f=1; break; }
while (s<e) s*=2,tmp++;
if (tmp>x) x=tmp;
if (n==1)
{
if (m!=1) f=1;
break;
}
}
if (f) { puts("-1"); continue; }
printf("%d\n",x);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  HDOJ ACM