hdu 5505 GT and numbers
GT and numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1520 Accepted Submission(s): 381
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.
题意:给出n和m,n每次和自身的因子相乘得到一个新的n,问最少多少次可使n==m
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 10100
#define INF 0x3f3f3f
#define LL unsigned long long
using namespace std;
LL gcd(LL a,LL b)
{
LL c;
while(b)
{
c=a%b;
a=b;
b=c;
}
return a;
}
int main()
{
LL n,m,j,i,t,k;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld",&n,&m);
if(n>m||n==0||m%n)
{
printf("-1\n");
continue;
}
if(n==m)
{
printf("0\n");
continue;
}
int flag=1;
k=0;
while(n!=m)
{
k++;
if(gcd(m/n,n)==1)
{
flag=0;
break;
}
n*=gcd(m/n,n);
}
if(flag)
printf("%lld\n",k);
else
printf("-1\n");
}
return 0;
}
hdu 5505 GT and numbers的更多相关文章
- HDU 5505——GT and numbers——————【素数】
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...
- hdu 5505(GT and numbers)
题意: 给你a和b,a每次和它的因子相乘得到一个新的a,求多少次后可以得到b. 输入样例 3 1 1 1 2 2 4 输出样例 0 -1 1 思路: 每次找出a和b/a的最大公约数(即当前a想得到b能 ...
- hdu 5272 Dylans loves numbers
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...
- hdu 5272 Dylans loves numbers 水题
Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...
- hdu 1058 dp.Humble Numbers
Humble Numbers Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Subm ...
- 数论 - 筛法暴力打表 --- hdu : 12876 Quite Good Numbers
Quite Good Numbers Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...
- hdu 5505(数论-gcd的应用)
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- BestCoder Round #60/HDU 5505 暴力数学
GT and numbers 问题描述 给出两个数NN和MM. NN每次可以乘上一个自己的因数变成新的NN. 求最初的NN到MM至少需要几步. 如果永远也到不了输出-1−1. 输入描述 第一行读入一个 ...
随机推荐
- adobe 蛋疼的套装, 想安装一个Flash Professional CS6,标准版还没有...
产品比较 查看内容 查看各 Creative Suite 6 版本的组件. Design Standard Design & Web Premium Production Premium Ma ...
- Android ActionBar隐藏修改图标和标题
有时候在一些子页面或者内容页面,不需要显示ActionBar的标题栏图标.可用如下方式进行设置. 首先获取到ActionBar对象 ActionBar actionBar=getActionBar() ...
- 【转】奇异值分解(We Recommend a Singular Value Decomposition)
文章转自:奇异值分解(We Recommend a Singular Value Decomposition) 文章写的浅显易懂,很有意思.但是没找到转载方式,所以复制了过来.一个是备忘,一个是分享给 ...
- ARMv7 .n和.w指令宽度指示符后缀
Thumb code里,.n后缀强迫生成16bit的代码,即Thumb code,若是在arm code里用.n会报错,若是机器指令没有办法用16表示也会报错 Thumb code里,.w后缀强迫生成 ...
- tap,touch,touchstart,事件与click事件的区别
根据源码所见, 移动端为了将将单击事件更加灵敏,所以现在的JQM,ST...框架都将JS单击事件封装成tap,或者touch或者touchstart事件, 其实现本质是将click触发多次,以打成移动 ...
- Android访问C#的WebService要注意的问题
@Overrideprotected String doInBackground(Object... params) { // 根据命名空间和方法得到SoapObject对象 SoapObject s ...
- python跟踪脚本进度(类似bash-x)
#详细追踪 python -m trace --trace jin.py #显示调用了哪些函数 python -m trace --trackcalls jin.py
- Can not perform pod install under el capitan (15A279b)
这个问题在stackoverflow上面有过讨论: Can not perform pod install under el capitan (15A279b) 被采纳的答案为:sudo gem in ...
- CSS sprite 圆角——源代码
所需图片: corner ...
- Win32汇编环境配置
放假了,发现自己知识面窄,趁有时间就打算折腾下Win32汇编.其实在学校也上过汇编课,是基于dos的.那时老师不务正业,老跟我们讲政治经济文化,唯独不怎么讲课;再加上自己的问题,导致了dos汇编学得好 ...