hdu5505
2015-10-24 13:19
295 查看
跟5504差不多。。。比赛的时候以为非常水。。。
其实确实挺水的。。。
比赛的时候不想写1000000的筛。。。
就直接对n分解质因数。。。
后来想了一下极限复杂度是nT。。。
【真是不知道脑子怎么长的 ←_←
写筛吧。。。不知道表会不会超长度。。。
这次我觉得我代码太屎了。。。
。。。随便看看就好。。。
最后。。。有个坑。。。就是m要unsigned long long。。。
其实确实挺水的。。。
比赛的时候不想写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; }
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- 2015 Multi-University Training Contest 6 Solutions
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- ACM题库以及培养策略