hdu 5505(数论-gcd的应用)
GT and numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1818 Accepted Submission(s): 490
Every step you can get a new N in the way that multiply N by a factor of N.
Work out how many steps can N be equal to M at least.
If N can't be to M forever,print −1.
In the next T lines there are two numbers N and M.
T≤1000, 1≤N≤1000000,1≤M≤263.
Be careful to the range of M.
You'd better print the enter in the last line when you hack others.
You'd better not print space in the last of each line when you hack others.
1 1
1 2
2 4
-1
1
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
typedef unsigned long long ULL;
ULL n,m;
ULL gcd(ULL a,ULL b){
return b==?a:gcd(b,a%b);
}
int main(){
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%llu%llu",&n,&m);
if(m%n!=||n==&&m!=) {
printf("-1\n");
continue;
}
if(m==n) {
printf("0\n");
continue;
}
int ans = ;
ULL t = m/n;
while(m!=n){
ULL d = gcd(n,t);
n = n*d;
t = t/d;
ans++;
if(d==) break;
}
if(m!=n) printf("-1\n");
else printf("%d\n",ans);
}
return ;
}
hdu 5505(数论-gcd的应用)的更多相关文章
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- UVA.12716 GCD XOR (暴力枚举 数论GCD)
UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...
- HDU 1722 Cake (数论 gcd)(Java版)
Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 ——每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2 . 然后 ...
- 【HDU 5382】 GCD?LCM! (数论、积性函数)
GCD?LCM! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- HDU - 5584 LCM Walk (数论 GCD)
A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. No ...
- HDU - 5974 A Simple Math Problem (数论 GCD)
题目描述: Given two positive integers a and b,find suitable X and Y to meet the conditions: X+Y=a Least ...
- [数论] hdu 5974 A Simple Math Problem (数论gcd)
传送门 •题意 一直整数$a,b$,有 $\left\{\begin{matrix}x+y=a\\ LCM(x*y)=b \end{matrix}\right.$ 求$x,y$ •思路 解题重点:若$ ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- HDU 5869 Different GCD Subarray Query (GCD种类预处理+树状数组维护)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5869 问你l~r之间的连续序列的gcd种类. 首先固定右端点,预处理gcd不同尽量靠右的位置(此时gc ...
随机推荐
- 【Nowcoder】玩游戏
Portal --> Nowcoder197D Solution 所以说这是一道==纯粹的人类智慧题是这样吗qwq 一开始的时候想sg函数qwq然后发现..好像根本不能拆成独立的子游戏嘛qw ...
- jsp中文乱码终极解决方法
转载http://blog.csdn.net/csh624366188/article/details/6657350 一 找出问题的根源 乱码可能出现的地方:1 jsp页面中 ...
- Codeforces 932.F Escape Through Leaf
F. Escape Through Leaf time limit per test 3 seconds memory limit per test 256 megabytes input stand ...
- php的自动加载函数spl_autoload_register和__autoload
spl_autoload_register和__autoload是用来自动加载类的,不用每次都require,include这样搞. 先说__autoload的用法, 在同级目录建立2个文件,一个in ...
- ubuntu如何杀死进程
一.得到所有进程 先用命令查询出所有进程 ps -ef 二.杀死进程 我们使用ps -ef命令之后,就会得到一些列进程信息,有进程pid什么的,如果你要杀死莫个进程的话,直接使用命令 kill ...
- bzoj 1430: 小猴打架
1430: 小猴打架 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 634 Solved: 461[Submit][Status][Discuss] ...
- DevExpress 常用命令包括导出-打印-打印预览等
3.表格打印也是最常见的,打印代码如下: PrintingSystem ps = null; DevExpress.XtraPrinting.PrintableComponentLink link = ...
- Spring Boot工程结构推荐
工程结构(最佳实践) Spring Boot框架本身并没有对工程结构有特别的要求,但是按照最佳实践的工程结构可以帮助我们减少可能会遇见的坑,尤其是Spring包扫描机制的存在,如果您使用最佳实践的工程 ...
- 2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)
题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbe ...
- nth-child,nth-last-child,only-child,nth-of-type,nth-last-of-type,only-of-type,first-of-type,last-of-type,first-child,last-child伪类区别和用法
我将这坨伪类分成三组,第一组:nth-child,nth-last-child,only-child第二组:nth-of-type,nth-last-of-type,第三组:first-of-tpye ...