GT and numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1803    Accepted Submission(s): 482

Problem Description

You are given two numbers N and M.

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.

 

Input

In the first line there is a number T.T is the test number.

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.

 

Output

For each test case,output an answer.
 

Sample Input

3
1 1
1 2
2 4
 

Sample Output

0
-1
1
 
 //2016.8.17
#include<iostream>
#include<cstdio>
#define ll unsigned long long
using namespace std; ll gcd(ll a, ll b)
{
return b==?a:gcd(b, a%b);
} int main()
{
int T, cnt;
bool fg;
ll n, m;
cin>>T;
while(T--)
{
scanf("%I64d%I64d", &n, &m);
if(n==m){
puts("");
continue;
}
if(n==||m<n||m%n!=)
{
puts("-1");
continue;
}
fg = true; cnt = ;
while(m != n)
{
ll tmp = gcd(n, m/n);
if(tmp == ){
fg = false;
break;
}
n *= tmp;
cnt++;
}
if(fg)
printf("%d\n", cnt);
else
printf("-1\n");
} return ;
}

HDU5505的更多相关文章

  1. hdu-5505(数论)

    题目链接: GT and numbers Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

随机推荐

  1. C#代码发送邮件

    本次测试的邮箱为163邮箱 1.首相对邮箱进行一些设置(详见下图):打开设置选取客户端授权密码项,开启设置:以后在客户端登录时将使用刚刚设置的密码! 2.上干货 public static void ...

  2. DBNull.value

    判断某一个datarow的cell是否有值需要进行两步判断 1.dr["field_name"]!=DBNull.value&&dr["field_nam ...

  3. 如何编译生成 dll

    原文:http://blog.csdn.net/qianchenglenger/article/details/21599235 版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[ ...

  4. java工程师联通XX面试题目

    什么是“长连接”和“短连接”? 所谓短连接指建立SOCKET连接后发送后接收完数据后马上断开连接,一般银行都使用短连接解释2长连接就是指在基于tcp的通讯中,一直保持连接,不管当前是否发送或者接收数据 ...

  5. 文本去重-----awk或者uniq

    对于awk '!a[$3]++',需要了解3个知识点 1.awk数组知识,不说了 2.awk的基本命令格式 awk 'pattern{action}'     省略action时,默认action是{ ...

  6. 2016年最全面的VR资源盘点,不只有VR视频播放器还有具体到步骤的VR资源

    2016年过去了,有多少人开始使用VR来观看我们喜欢的视频资源呢?比传统视频更高的沉浸感,甚至在VR眼镜的视角中,自己仿佛化生成视频中的主角一般.然而,这种体验只有VR眼镜还是不行的,还需要有一个VR ...

  7. js-权威指南学习笔记8

    第8章 函数 1.参数有形参和实参的区别,形参相当于函数中定义的变量,实参是在运行时的函数调用时传入的参数. 2.函数表达式可以包含名称,这在递归时很有用. 3.函数定义表达式特别适合用来定义那些只会 ...

  8. 安装了C

    2014-04-09 13:19:30 大学里看的第一本编程书籍,就是C.但是一直没有编译. 今天首次安装,我也佩服当初我是怎么通过C二级的. 上午写了sds手册.其中的制图用的visio制图,非常好 ...

  9. Leetcode 181. Employees Earning More Than Their Managers

    The Employee table holds all employees including their managers. Every employee has an Id, and there ...

  10. UVa 10700 - Camel trading

    题目大意:给一个不含括号.只有+和*运算的表达式,数字的范围在1到20之间,算出计算结果的可能最大值和最小值. 贪心,如果加法优先级比乘法高,那么得出的结果为最大值.(a+b)*c = a*c + b ...