题目传送门

题意:有一个A进制的有限小数,问能否转换成B进制的有限小数

分析:0.123在A进制下表示成:1/A + 2/(A^2) + 3 / (A^3),转换成B进制就是不断的乘B直到为0,即(1/A + 2/(A^2) + 3 / (A^3)) * (B^m)。那么(B^m) 一定要能整除(A^n),转换一下就是A的质因子B都有,可以用GCD高效计算

收获:数论题做不来可以找找规律,想想会用什么知识求解

代码:

/************************************************
* Author :Running_Time!
* Created Time :2015-8-25 8:49:59
* File Name :A.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int MAXN = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7; ll GCD(ll a, ll b) {
return b == 0 ? a : GCD (b, a % b);
} int main(){
int T, cas = 0; scanf ("%d", &T);
ll A, B, C;
while (T--) {
scanf ("%I64d%I64d", &A, &B);
while ((C = GCD (A, B)) != 1) A /= C;
printf ("Case #%d: %s\n", ++cas, A == 1 ? "YES" : "NO");
} return 0;
}

  

最新文章

  1. C main
  2. C#使用Expand、Shell32解压Cab、XSN文件
  3. 【POJ 1182 食物链】并查集
  4. jQuery(二)
  5. linux定时调度器每秒运行一次
  6. Best jQuery Plugins of the Month – May 2014
  7. 需求分析&amp;原型改进
  8. POJ1017 Packets---贪心
  9. 3D数学 矩阵常用知识点整理
  10. Three failed attempts of handling non-sequential data
  11. FPGA——入手(零)
  12. Perl的IO操作(2):更多文件句柄模式
  13. 6.方法_EJ
  14. vCenter server 的部署和实施
  15. Android 简历 怎么写? 月薪10K,20K+, 怎么拿到面试?
  16. ORM框架之SQLALchemy
  17. 【驱动】Flash设备驱动基础&#183;NOR&#183;NAND
  18. python import win32clipboard 报错DLL load failed: %1 不是有效的 Win32 应用程序。
  19. Python系列之入门篇——pytables及其客户端
  20. Jetty - Connector源码分析

热门文章

  1. 【Nginx】基本数据结构
  2. UI 经常用法总结之--- UILabel UITextField (不断更新中)
  3. Robotframework集成jenkins执行用例
  4. fedora下安装xdot和objgraph
  5. OTG识别原理
  6. C语言将10进制转为2进制
  7. C实现头插法和尾插法来构建单链表(不带头结点)
  8. 1 TypeScript 简介与安装
  9. eclipse下对中文乱码问题的一些思考
  10. Python爬虫开发【第1篇】【爬虫案例】