GT and numbers

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

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
 
Source
 

题目大意:

解题思路:

#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<limits.h>
using namespace std;
typedef unsigned long long UINT;
const int maxn = 1e6+2000;
UINT prime[maxn];
void getprime(){
prime[0] = 1; prime[1] = 1;
for(UINT i = 2; i*i <= maxn-10; i++){
if(!prime[i])
for(int j = i*i; j <= maxn-10 ;j += i){
prime[j] = 1;
}
}
}
int main(){
int T;
getprime();
scanf("%d",&T);
UINT a,b;
while(T--){
scanf("%llu%llu",&a,&b);
if(b < a){
puts("-1");
}else if(b == a){
puts("0");
}else{
if(a == 1 || b%a != 0){
puts("-1");
}else{
b /= a;
int sum = 0;
for(UINT i = 2; i <= maxn-100; i++){
if(prime[i]) continue;
UINT tmp = 1 , times = 0;
if(a % i != 0) continue;
while(a % i == 0){
a /= i;
tmp *= i;
}
while(b % tmp == 0){
b /= tmp;
tmp *= tmp;
times ++;
}
if(b % i == 0){
sum = times+1 > sum? times+1:sum;
while( b % i == 0){
b /= i;
}
}else{
sum = times > sum? times:sum;
}
if(b == 1){
break;
}
}
if(b == 1){
printf("%d\n",sum);
}else{
puts("-1");
}
}
}
}
return 0;
}

  

 

HDU 5505——GT and numbers——————【素数】的更多相关文章

  1. hdu 5505 GT and numbers

    GT and numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  2. POJ 2739 Sum of Consecutive Prime Numbers(素数)

    POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...

  3. HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  4. HDU 5505 - BestCoder Round #60 - GT and numbers

    题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...

  5. hdu 5505(GT and numbers)

    题意: 给你a和b,a每次和它的因子相乘得到一个新的a,求多少次后可以得到b. 输入样例 3 1 1 1 2 2 4 输出样例 0 -1 1 思路: 每次找出a和b/a的最大公约数(即当前a想得到b能 ...

  6. 数论 - 筛法暴力打表 --- hdu : 12876 Quite Good Numbers

    Quite Good Numbers Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...

  7. hdu 5272 Dylans loves numbers

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...

  8. hdu 5272 Dylans loves numbers 水题

    Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...

  9. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

随机推荐

  1. 进程vs线程

    内存中的内容不同 进程->{ 进程是系统分配资源的最基本单位,线程是进程的一部分, 进程中存储文件和网络句柄 } 线程->{ 栈(每个线程都有一个栈空间) pc(当前或下一条指令的地址,指 ...

  2. 浏览器怎么禁用和开启Javascript

    转自;http://360.bgu.edu.cn/help/openJsHelp.html IE内核的浏览器禁用和启用Javascript功能都类似,首先我们需要打开IE8浏览器. 之后点击其右上角的 ...

  3. rsyn文件传输

    Rsync的命令格式可以为以下六种: rsync [OPTION]... SRC DEST rsync [OPTION]... SRC [USER@]HOST:DEST rsync [OPTION]. ...

  4. Hander----使用

    public class MainActivity extends Activity { private EditText UITxt; private Button updateUIBtn; pri ...

  5. [poj2104]可持久化线段树入门题(主席树)

    解题关键:离线求区间第k小,主席树的经典裸题: 对主席树的理解:主席树维护的是一段序列中某个数字出现的次数,所以需要预先离散化,最好使用vector的erase和unique函数,很方便:如果求整段序 ...

  6. xgene:肿瘤相关基因 KRAS,,BRAF,,通路PI3K-AKT

    KRAS基因 一个是KRAS1,位于chr6 短臂上,是一个“假基因”,它不能被转录成RNA,故没有功能的 另一个是KRAS2,位于chr12 短臂上..是“真基因”,是能够转录.并且翻译成蛋白的,是 ...

  7. 36、EST-SSR标记开发

    转载:http://fhqdddddd.blog.163.com/blog/static/1869915420124131096557/ MISA工具提供批量识别和定位简单重复序列(SSR),EST序 ...

  8. 2.HTTP头注入

    重新认识被人遗忘的HTTP头注入 前言 注入类漏洞经久不衰,多年保持在owasp Top 10的首位.今天就聊聊那些被人遗忘的http头注入.用简单的实际代码进行演示,让每个人更深刻的去认识该漏洞. ...

  9. 业务、数据记录——ThreadPool.QueueUserWorkItem及Redis的实现

    业务描述 当用户执行完业务操作,或者数据操作后,讲业务记录/数据追踪插入到Redis中.ThreadPool.QueueUserWorkItem定时检查队列并将上述数据插入到数据库中持久化. 实现流程 ...

  10. C#中的自动属性、隐式类型var、对象初始化器与集合初始化器、扩展方法

    1.自动属性(Auto-Implemented Properties) //以前的写法 .net2.0 private string _userName; public string UserName ...