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. xcode 6 出现的新问题

    1.prefix.pch文件的使用 [1].需要自己创建 点击new file-->选择IOS中的Other选项卡,选择PCH File [2].创建完后需要设置一下才能成功 Prefix He ...

  2. ELK 日志分析体系

    ELK   日志分析体系 ELK 是指 Elasticsearch.Logstash.Kibana三个开源软件的组合. logstash                       负责日志的收集,处 ...

  3. redis sentinel 集群监控 配置

    环境: ip  172.16.1.31 26379  redis sentinel ip  172.16.1.30 6379   主 1 ip  172.16.1.31 6380   从 1 ip   ...

  4. LNMP(Linux+Nginx+Mysql+PHP---源码)环境搭建

    LNMP(Linux+Nginx+Mysql+PHP(Perl)) Linux:[root@dep5 mysql]# cat /etc/issueRed Hat Enterprise Linux Se ...

  5. (简单) POJ 3074 Sudoku, DLX+精确覆盖。

    Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgr ...

  6. MySQL中 InnoDB 和 MyISAM 小结

    转:http://blog.csdn.net/ithomer/article/details/5136982 部分内容: InnoDB和MyISAM的差别 InnoDB和MyISAM是许多人在使用My ...

  7. mysql root密码

    方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...

  8. ucos事件邮箱信号量队列详解

    Ucos的事件分为时钟,信号量,互斥性信号量,消息队列,以及消息邮箱 首先说信号量 信号量在ucos中的类型定义为OS_EVENT_TYPE_SEM,在任务控制块ecb中,主要是用到的是信号量计数器O ...

  9. LPC2478内存布局以及启动方式

    LPC2478 是NXP公司推出的一款基于APR7TDMI-S的工控型MCU,内置RAM与flash,同时提供外部扩展flash和ram接口,拥有LCD控制器,其内存布局如下所示 其中Flash高达5 ...

  10. tp框架

    <?php namespace Admin\Controller; use Think\Controller; class DengluController extends Controller ...