题目传送门

题意:有一个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;
}

  

数论(GCD) HDOJ 4320 Arcane Numbers 1的更多相关文章

  1. HDU 4320 Arcane Numbers 1 (数论)

    A - Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  2. HDU 4320 Arcane Numbers 1(质因子包含)

    http://acm.hdu.edu.cn/showproblem.php?pid=4320 题意: 给出A,B,判断在A进制下的有限小数能否转换成B进制下的有限小数. 思路: 这位博主讲得挺不错的h ...

  3. HDU 4320 Arcane Numbers 1 (质因子分解)

    题目:传送门. 题意:将一个A进制下的有限小数转化为B进制看是否仍为有限小数. 题解:一个A进制的小数可以下次 左移动n位变成A进制整数然后再将其转化为B进制即可 即B^m/A^n要整除,因此A的质因 ...

  4. 2012 #3 Arcane Numbers

    Arcane Numbers 1 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Su ...

  5. Arcane Numbers 1

    Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers& ...

  6. 找规律/数位DP HDOJ 4722 Good Numbers

    题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...

  7. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  8. hdu 5505(数论-gcd的应用)

    GT and numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  9. CF1025B Weakened Common Divisor【数论/GCD/思维】

    #include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...

随机推荐

  1. Ulua_toLua_基本案例(一)

    Ulua_toLua_基本案例 在Untiy中用Lua.必需要LuaInterface.LuaInterface的介绍请看:点击打开链接 能够先光写Lua,生成.lua的纯文件.再Unity中通过,l ...

  2. 数据库分表和分库的原理及基于thinkPHP的实现方法

    为什么要分表,分库: 当我们的数据表数据量,訪问量非常大.或者是使用频繁的时候,一个数据表已经不能承受如此大的数据訪问和存储,所以,为了减轻数据库的负担,加快数据的存储,就须要将一张表分成多张,及将一 ...

  3. 看懂JSP声明的格式。。。

    在WebRoot下新建test3.jsp 改动body内容: <%! int a = 3; %>     <% int b = 3; %>     <%= a--  %& ...

  4. hdu2099 整除的位数(暴力)

    Problem Description http://acm.hdu.edu.cn/showproblem.php?pid=2099 一个整数,仅仅知道前几位.不知道末二位,被还有一个整数除尽了,那么 ...

  5. JDK各版本内容和新特性

    JDK各版本内容和新特性 - yanlzhl - 博客园 https://www.cnblogs.com/yanlzhl/articles/5694470.html    版本JDK1.0:1995年 ...

  6. 设置一个DIV块固定在屏幕中央(两种方法)

    设置一个DIV块固定在屏幕中央(两种方法) 方法一: 对一个div进行以下设置即可实现居中. <style> #a{ position: fixed; top: 0px; left: 0p ...

  7. 在VS2010下使用AppFace

    AppFace的介绍网上一大堆,此文仅为自己作个记录,方便以后查看. 一.需要的文件:1.AppFace.h  2.appface.lib 3.appface.dll 4.macosx_af.urf ...

  8. Buildroot用户指南【转】

    本文转载自:http://www.voidcn.com/blog/bytxl/article/p-4727302.html 第一章        关于Buildroot Buildroot是一个包含M ...

  9. wirte function in powershell

    https://github.com/dahlbyk/posh-git/blob/master/src/Utils.ps1#L102 https://docs.microsoft.com/en-us/ ...

  10. YTU 2952: A代码填充--谁挡住了我

    2952: A代码填充--谁挡住了我 时间限制: 1 Sec  内存限制: 128 MB 提交: 135  解决: 38 题目描述 n个人前后站成一列,对于队列中的任意一个人,如果排在他前面的人的身高 ...