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 ...
随机推荐
- httpd或Nginx负载均衡tomcat
实验环境:CentOS7 #两台tomcat的基本配置如下: [root@webapps localhost]#setenforce 0 [root@webapps localhost]#iptabl ...
- mybatis---demo1--(1-n)----bai
实体类1: package com.etc.entity; import java.util.List; public class Teacher { private int tid; private ...
- sql server 2008 开启1433端口,开启远程连接
通常情况下只需要设置两处
- 3.JasperReports学习笔记3-在浏览器生成PDF文件
转自:https://i.cnblogs.com/posts?categoryid=921197 一.新建web工程,导入jasperreports所需的jar包,配置web.xml <serv ...
- JAVA基础知识总结2(语法基础)
关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:暂时还未规定为关键字的单词,保留准备日后要使用的单词. 标识符:开发人员程序中自定义名词,比如类名,变量名,函数名. PS:1.不能使用关键字. ...
- 【总结整理】http-https
上面这种加密消息的方式就是对称加密,你知道如何加密,也知道如何解码.然后李雷跟韩梅梅用的字母表偏移的加密方法叫 Caesar cipher, 凯撒加密.现实世界中用的加密算法会更复杂,但是基本原理相同 ...
- c# 创建缩略图
/// <summary> /// 创建缩略图 /// </summary> /// <param name="srcFileName">< ...
- Hadoop YARN配置参数剖析(3)—MapReduce相关参数
MapReduce相关配置参数分为两部分,分别是JobHistory Server和应用程序参数,Job History可运行在一个独立节点上,而应用程序参数则可存放在mapred-site.xml中 ...
- Ubuntu W: GPG 错误:下列签名无效: BADSIG 84DBCE2DCEC45805 Launchpad PPA fo
Ubuntu12.04 安装R语言的时候出现的报错. 研究了两个晚上,解决办法如下,跟参考贴有点出入: ############################################### ...
- 阶段2-新手上路\项目-移动物体监控系统\Sprint2-摄像头子系统开发\第2节-V4L2图像编程接口深度学习
参考资料: http://www.cnblogs.com/emouse/archive/2013/03/04/2943243.htmlhttp://blog.csdn.net/eastmoon5021 ...