数论(GCD) HDOJ 4320 Arcane Numbers 1
题意:有一个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的更多相关文章
- HDU 4320 Arcane Numbers 1 (数论)
A - Arcane Numbers 1 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64 ...
- HDU 4320 Arcane Numbers 1(质因子包含)
http://acm.hdu.edu.cn/showproblem.php?pid=4320 题意: 给出A,B,判断在A进制下的有限小数能否转换成B进制下的有限小数. 思路: 这位博主讲得挺不错的h ...
- HDU 4320 Arcane Numbers 1 (质因子分解)
题目:传送门. 题意:将一个A进制下的有限小数转化为B进制看是否仍为有限小数. 题解:一个A进制的小数可以下次 左移动n位变成A进制整数然后再将其转化为B进制即可 即B^m/A^n要整除,因此A的质因 ...
- 2012 #3 Arcane Numbers
Arcane Numbers 1 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Su ...
- Arcane Numbers 1
Vance and Shackler like playing games. One day, they are playing a game called "arcane numbers& ...
- 找规律/数位DP HDOJ 4722 Good Numbers
题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数 ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- hdu 5505(数论-gcd的应用)
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- CF1025B Weakened Common Divisor【数论/GCD/思维】
#include<cstdio> #include<string> #include<cstdlib> #include<cmath> #include ...
随机推荐
- vim配置为IDE环境(超详细,极力推荐 git)
https://github.com/yangyangwithgnu/use_vim_as_ide 1. 用法 git clone https://github.com/VundleVim/Vundl ...
- CentOS 6.x ELK(Elasticsearch+Logstash+Kibana)
CentOS 6.x ELK(Elasticsearch+Logstash+Kibana) 前言 Elasticsearch + Logstash + Kibana(ELK)是一套开源的日志管理方案, ...
- HDU 1824 Let's go home (2-SAT判定)
Let's go home Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 【iOS系列】-文件管理
OC中操作文件,需要使用NSFileManager: 需要使用NSFileManager的创建方式: //单例模式创建对象 NSFileManager * f2 = [NSFileManager de ...
- bzoj3109【CQOI2013】新数独
3109: [cqoi2013]新数独 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 365 Solved: 229 [Submit][Statu ...
- asp.net listview 实现分页浏览效果
页面代码: <div style="margin-top:0px;">共<asp:Label ID="lb_count" runat=&quo ...
- tunctl和虚拟网卡
1 tun/tap驱动 1.1 网卡驱动 同tcp/ip协议栈打交道,接受和发送数据包 1.2 字符驱动 内核和用户态通过字符设备交换数据包. 2 tun虚拟网卡的创建 tunctl -t tun0 ...
- Module in powershell
https://docs.microsoft.com/en-us/powershell/module/powershellget/install-module?view=powershell-6 ht ...
- CollectionView旋转水平卡片布局
概述 UICollectionView真的好强大,今天我们来研究一下这种很常见的卡片动画效果是如何实现了.本篇不能太深入地讲解,因为笔者也是刚刚摸索出点眉目,但是并没有深刻地理解.如果在讲解过程中,出 ...
- I.MX6 AW-NB177NF wifi HAL 调试修改
/************************************************************************* * I.MX6 AW-NB177NF wifi H ...