HDU 5505——GT and numbers——————【素数】
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
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.
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.
题目大意:
解题思路:
#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——————【素数】的更多相关文章
- hdu 5505 GT and numbers
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- 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 ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...
- 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能 ...
- 数论 - 筛法暴力打表 --- hdu : 12876 Quite Good Numbers
Quite Good Numbers Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit ...
- hdu 5272 Dylans loves numbers
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5272 Dylans loves numbers Description Who is Dylans?Y ...
- hdu 5272 Dylans loves numbers 水题
Dylans loves numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem. ...
- CodeForces 385C Bear and Prime Numbers 素数打表
第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...
随机推荐
- kvm虚拟机命令梳理
kvm虚拟机命令梳理 )查看KVM虚拟机配置文件及运行状态 KVM虚拟机默认配置文件位置: /etc/libvirt/qemu/ autostart目录是配置kvm虚拟机开机自启动目录. virsh命 ...
- for循环及break和continue的区别
1.For循环 格式: for( 初始语句 ; 执行条件 ; 增量 ){ 循环体 } 执行顺序:1.初始语句 2.执行条件是否符合 3.循环体 4.增加增量 初始化语句只在循环开始前执行一次,每次 ...
- eclipse tomcat 无法加载导入的web项目,There are no resources that can be added or removed from the server. .
应该是项目自己的setting文件夹下的描述信息和.project文件的描述信息,不能适用于这个eclipse和tomcat. 解决方法: 1,找相同类型的工程(tomcat能引用的)2,把新建项目里 ...
- java try catch 与 throws 使用场景以及怎么合理使用?
对于如下场景,给出不同的看法: 其实我更多的疑问在于,自定义的方法里面java api抛出了异常,这个时候,我是需要捕获呢?还是我也继续往上抛. 比如,我这里定义了一个日期处理的方法,有两种对异常的处 ...
- 全面解析JS字符串和正则表达式中的match、replace、exec等函数
转自:https://www.jb51.net/article/87730.htm 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检查一个串是否含有某种子串.将 ...
- linux命令-rpm安装和卸载
软件包 先查看一下rpm包 [root@wangshaojun Packages]# mount /dev/cdrom /mnt/////挂载[root@wangshaojun Packages]# ...
- Spring的概况
----------------siwuxie095 Spring 的简介 Spring 是一个轻量级 控制反转(IoC) 和 面向切面(AOP) 的容器框架 年,它是为了解决企业应用开发的复杂性而诞 ...
- 12、IGV-Integrative Genomics Viewer
1.IGV的网址:http://software.broadinstitute.org/software/igv/(java环境) 常见的几种输入格式bam/sam(比对文件) TDF(bam的精简 ...
- 为什么ps中CPU占用率会有超出%100的现象?
前面的关于ps中的%CPU的含义一文已经介绍了CPU占用率的含义,那么为什么有时会在ps的输出中看到CPU占用率超出%100的现象呢?我们知道在/proc目录下每个进程都会有一个以它的PID以名字的目 ...
- 【mysql格式化日期】
date_format(now(),'%Y-%c-%d'): 1. DATE_FORMAT() 函数用于以不同的格式显示日期/时间数据. DATE_FORMAT(date,format) format ...