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. linux下 mysql 学习(一)

    1.登录mysql [root@test1 local]# mysql  Welcome to the MySQL monitor. Commands end with ; or g. Your My ...

  2. Cocos2dx 3.1.1 将一个2.X的项目改成3.1版本

    最近在论坛上下载到了一个Cocos2dx的单机跑酷例子, 也不知道是2.x版的, 花了一天时间试着把他改成3.1.1的试试, 现在已经可以顺利编译的, 但是还是有Heap Free的问题,调试了好几天 ...

  3. codis 新版本 CodisLabs 编译安装

    codis 3.0 版本编译安装 # 首先安装 go 语言 wget https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz ...

  4. java数组的声明由几种方式

    数组的声明由几种方式: 1,String []a = new String[length];再赋值 a[0]=?;....... 2,new完就直接初始化: String []a = new Stri ...

  5. IOS小技巧——使用FMDB时如何把一个对像中的NSArray数组属性存到表中

    http://blog.csdn.net/github_29614995/article/details/46797917 在开发的当中,往往碰到要将数据持久化的时候用到FMDB,但是碰到模型中的属性 ...

  6. iOS给自定义个model排序

    今天有朋友问我怎么给Model排序,我顺便写了一个,伸手党直接复制吧. 例如,我建了一个Person类,要按Person的年龄属性排序: Person *per = [[Person alloc] i ...

  7. linux命令学习7-jstat命令

    最近维护的项目使用的是java开发的,所以对于jvm虚拟机相关的操作还是必须要了解的,就先从最基本的jstat来学习起来. 首先需要会的就是full gc的查看; 下面就从网上收集了一些工具介绍, 慢 ...

  8. 《算法导论》插入排序----InsertSort

    算法导论,插入排序 public class InsertSort { public static double [] sort(double [] num) { for(int i =1; i< ...

  9. mysql 安装错误 解决方法

    错误及警告信息:TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_time ...

  10. 浅谈MySQL分表

    关于分表:顾名思义就是一张数据量很大的表拆分成几个表分别进行存储. 我们先来大概了解以下一个数据库执行SQL的过程: 接收到SQL --> 放入SQL执行队列 --> 使用分析器分解SQL ...