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. javascript 实现加法分离。 plus(3)(4); // => 得到 7

    原文地址:http://cnodejs.org/topic/5230d5f0101e574521c86ff4 JavaScript 的设计是典型的函数式的编程范式匿名函数 JSON数据本身就是字符串, ...

  2. python自动发邮件总结及实例说明

    python发邮件需要掌握两个模块的用法,smtplib和email,这俩模块是python自带的,只需import即可使用.smtplib模块主要负责发送邮件,email模块主要负责构造邮件. sm ...

  3. js url校验

    function IsURL(str_url){ var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9 ...

  4. ibatis参数传递小技巧 - 疯狂的菠菜 - ITeye技术网站

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  5. DDR工作原理(转)

    源:DDR工作原理 DDR SDRAM全称为Double Data Rate SDRAM,中文名为“双倍数据流SDRAM”.DDR SDRAM在原有的SDRAM的基础上改进而来.也正因为如此,DDR能 ...

  6. uses crt;

    1.uses CRT,表示引用CRT.pas单元.CRT.pas单元是Pascal最重要的单元之一,主要用于字符界面的操作,里面内置了清屏.光标定位.删除行.调整字符亮度.前景色.背景色等功能函数.2 ...

  7. ucos任务控制块详解

    Ucos实现多任务的基础包括几个方面:任务控制块,任务堆栈,中断,任务优先级,一一说起 首先,任务控制块的结构如下 //系统在运行一个任务的时候,按照任务的优先级获取任务控制块,再在任务堆栈中获得任务 ...

  8. android NDK编译(导入).a文件和编译多个so文件(转)

    源:android NDK编译(导入).a文件和编译多个so文件 一.编译一个静态库 libstatic_android.a LOCAL_PATH := $(call my-dir) include ...

  9. iOS动画特效 分类: ios技术 2015-05-15 16:29 311人阅读 评论(0) 收藏

    关于图层的几个坐标系. 对于ios来说,坐标系的(0,0)点在左上角,就是越往下,Y值越大.越往右,X值越大. 一个图层的frame,它是position,bounds,anchorPoint和tra ...

  10. make的参数

    转载自 陈皓<跟我一起写 Makefile> 下面列举了所有GNU make 3.80版的参数定义.其它版本和产商的make大同小异,不过其它产商的make的具体参数还是请参考各自的产品文 ...