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. 九 fork/join CompletableFuture

    1: Fork/join fork/join:  fork是分叉的意思, join是合并的意思. Fork/Join框架:是JAVA7提供的一个用于并行执行任务的框架,是一个把大任务分割成若干个小任务 ...

  2. linux strace-跟踪进程的系统调用或是信号产生情况,lstrace-跟踪己丑年调用库函数情况,进程跟踪调试命令

    本工具可以用来做大多数排除,比如mount一个NFS,很慢,找不出原因,我们可以使用strace命令来跟中mount这个经常所有的调用过程. strace 命令是一种强大的工具,它能够显示所有由用户空 ...

  3. mysql数据库之表与表之间的关系

    表1 foreign key 表2 则表1的多条记录对应表2的一条记录,即多对一 利用foreign key的原理我们可以制作两张表的多对多,一对一关系 多对多: 表1的多条记录可以对应表2的一条记录 ...

  4. 分页sql汇总

    1.oracle数据库分页 select * from (select a.*,rownum rc from 表名 where rownum<=endrow) a where a.rc>= ...

  5. Antiprime数-数论

    题目描述 Description 如果一个自然数n满足:所有小于它的自然数的约数个数都小于n的约数个数,则称n是一个Antiprime数.譬如:1.2.4.5.12.24都是Antiprime数.   ...

  6. linux下将编译错误输出到一个文本文件

    linux下将编译错误输出到一个文本文件 command > filename 把把标准输出重定向到一个新文件中 command > > filename 把把标准输出重定向到一个文 ...

  7. BZOJ4085: [Sdoi2015]音质检测

    BZOJ4085: [Sdoi2015]音质检测 由于这题太毒了,导致可能会被某些人卡评测,于是成了一道权限题... 本蒟蒻表示没钱氪金... 但是可以去洛谷/Vijos搞搞事... 但是洛谷上只能评 ...

  8. elasticsearch 复合查询

    常用查询 固定分数查询 127.0.0.1/_search(全文搜索) { "query":{ "match"{ "title":" ...

  9. Entity Framework Code-First(9.5):DataAnnotations - MaxLength Attribute

    DataAnnotations - MaxLength Attribute: MaxLength attribute can be applied to a string or array type ...

  10. Entity Framework Code-First(1):Introduction

    Entity Framework Code-First: Learn Entity Framework Code-First in simple step-by-step tutorials. The ...