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. CentOS 7 x64 docker 使用点滴

    CentOS 7 安装 docker yum search docker  查看是否 有docker包 yum info docker  版本为1.3.2 yum -y install docker ...

  2. 酷炫的方块状散点3D

    http://threejs.org/examples/webgl_particles_random.html

  3. PHP学习笔记-1——快捷键

    整行删除 ctrl+E set get 生成 alt+ insert 查找.搜索和替换 Ctrl-F3 搜索位于插入点的词 F3/Shift-F3 在文件中查找下一个/上一个 Ctrl-F/H 在文件 ...

  4. MariaDB GTID 复制同步

    MariaDB GTID 复制同步 GTID:Global Transaction ID,全局事务ID,在整个主从复制架构中任何两个事物ID是不能相同的.全局事务ID是Mster服务器生成一个128位 ...

  5. Delphi中unicode转汉字函数(转)

    源:Delphi中unicode转汉字函数 近期用到这个函数,无奈没有找到 delphi 自带的,网上找了下 有类似的,没有现成的,我需要的是 支持 “\u4f00 ” 这种格式的,即前面带标准的 “ ...

  6. Vue.js起步

    Vue.js是一套构建用户界面的 渐进式框架,Vue 采用自底向上增量开发的设计,Vue 的核心库只关注视图层.Vue 完全有能力驱动采用单文件组件和 Vue 生态系统支持的库开发的复杂单页应用. V ...

  7. YUM更换源(1)--yum找不到安装包

    公司提供的CentOS VM中,/etc/yum.repos.d 下 只有一个build.repo,其中提供的yum 源只有公司内部的几个源,很多包在这些源中都找不到.于是要添加别的源,下面的帖子中介 ...

  8. Memcached源码分析之请求处理(状态机)

    作者:Calix 一)上文 在上一篇线程模型的分析中,我们知道,worker线程和主线程都调用了同一个函数,conn_new进行事件监听,并返回conn结构体对象.最终有事件到达时,调用同一个函数ev ...

  9. 今天学习了下,如何破解wifi

    破解了隔壁的wif,得罪了,哥哥要蹭网一段时间. 主要思路:安装linux环境.这里我选择了虚拟机加cdlinux .运行里面的min抓得握手包,然后淘宝花10元跑下包,因为自己的电脑不行,跑费时间太 ...

  10. BZOJ1419: Red is good

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 639  Solved: 247[Submit][Status][Di ...