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
- hdu5505
- hdu5505
- hdu5505
- hdu5505(好题)
- hdu5505 GT and numbers
- hdu5505 GT and numbers(BestCoder Round #60)
- BestCoder Round #60 HDU5505 GT and numbers
- hdu5505 GT and numbers(贪心)
- 善行100——爱心包裹捐助
- ZOJ 1586 QS Network(最小生成树 Prim)
- 九度OJ 1148:Financial Management(财务管理) (平均数)
- #define M(row,col) m[col*4+row]宏定义代码全解
- thinkst 视频搜索网站
- hdu5505
- 肖特基二极管
- 写让别人能读懂的代码
- 【Virtualbox】开启虚拟化
- 九度OJ 1149:子串计算 (计数、排序)
- Apache Mesos【一】Apache Mesos的整体架构
- hibernate HQL new xxx() 查询 join连接多个表,并把连接后的表保存到一个新类中
- input_set_abs_params
- Android属性动画完全解析(二)