HDU 4320 Arcane Numbers 1
来源:互联网 发布:阿里云如何关闭快照 编辑:程序博客网 时间:2024/06/05 10:55
Arcane Numbers 1
题意:给出A,B(<=10^12) ,问能否将A进制下的有限小数转化为B进制下的有限小数。A进制下的小数可以表成:sum(ai*1/(A^i)),化成B进制就是要不断的乘以B,所以B^m/(A^n)必须被整除。所以我们只需要判断A中的质因子是否都在B中出现,如果在则可以转化,否则不能。
/* author : csuchenan prog : hdu 4320 algorithm: 整数分解*/#include <cstdio>#include <cstring>#include <vector>using std::vector;typedef long long LL;vector<LL> pr;// 用于存放素数vector<LL> pf;// 用于存放A的因子const int maxn = 1000000;bool prim[maxn+5];void getPrim(){ for(int i = 2; i <= maxn ; i ++){ if(!prim[i]){ pr.push_back(i) ; for(int j = i + i; j <= maxn; j +=i){ prim[j] = true; } } }}bool solve(LL a, LL b){ //getFactors pf.clear(); for(int i = 0; (LL)pr[i]*pr[i] <= a && i != pr.size(); i ++){ if(a%pr[i]==0){ pf.push_back(pr[i]); while(a%pr[i]==0){ a = a/pr[i]; } } } if(a > 1) pf.push_back(a) ; for(int i = 0; i != pf.size(); i ++){ if(b%pf[i] != 0) return false; } return true;}int main(){ int T, cas=1; LL A, B;// freopen("test.in", "r", stdin); getPrim(); scanf("%d", &T); while(T--){ scanf("%I64d%I64d", &A, &B); printf("Case #%d: ", cas ++); if(B%A==0 || solve(A, B)){ puts("YES"); } else{ puts("NO"); } } return 0;}
- hdu 4320 Arcane Numbers 1
- hdu 4320 Arcane Numbers 1
- HDU - 4320 Arcane Numbers 1
- HDU 4320 Arcane Numbers 1
- HDU 4320 Arcane Numbers 1
- hdu - 4320 - Arcane Numbers 1 - 想法题
- HDU 4320 Arcane Numbers 1 (数论)
- HDU 4320 - Arcane Numbers 1 / SWUN 1429 - 进制转化
- HDU 4320 Arcane Numbers 1(12年多校3-数学)
- hdu 4320 Arcane Numbers 1 多校联合赛(三)第一题
- hdu 4320 Arcane Numbers 1(小数进制转化后是否有限位)
- hdu - 4321 - Arcane Numbers 2 - 数位统计
- 2012 Multi-University Training Contest 3:Arcane Numbers 1
- hdu4320 Arcane Numbers 1(小数进制转换)
- HDU 4321 Arcane Numbers 2 按位处理, 想法计数题
- Numbers HDU
- 质因数:arcane number1
- HDU 3117 Fibonacci Numbers
- U盘容量变小,重新分区
- C++常用库函数
- 简明Vim练级攻略
- 使用弹性盒布局来实现元素宽度与高度的自适应
- android记录和恢复ListView滚动的位置
- HDU 4320 Arcane Numbers 1
- ATL揭秘之“对象创建”
- RO IOCP开发心得系列(01):服务器程序防止Socket攻击的解决方案
- C++“靠近定义变量“之真正原因
- Shell 基础大全
- 解决win下eclipse连linux的hadoop集群连不上的问题
- Sql Server按树形结构排序查询表记录(CSDN论坛转载)
- HTTP method POST is not supported by this URL
- 求两点间的距离