hdu5505

来源:互联网 发布:两心淘宝小号 编辑:程序博客网 时间:2024/06/03 05:17

跟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;}


0 0
原创粉丝点击