BestCoder Round #60/HDU 5505 暴力数学
GT and numbers
给出两个数NN和MM。
NN每次可以乘上一个自己的因数变成新的NN。
求最初的NN到MM至少需要几步。
如果永远也到不了输出-1−1。
第一行读入一个数TT表示数据组数。
接下来TT行,每行两个数NN和MM。
T\leq1000T≤1000, 1\leq N \leq 10000001≤N≤1000000,1 \leq M \leq 2^{63}1≤M≤263. 注意M的范围。hack时建议输出最后一行的行末回车;每一行的结尾不要输出空格。
对于每组数据,输出一个数表示答案。
3
1 1
1 2
2 4
0
-1
1 题解:对n质数分解成x个指数因子,再对m进行整除到底,知道所得m为1为止,记录步数ans就是答案,否则-1;
///
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
using namespace std ;
typedef unsigned long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define memfy(a) memset(a,-1,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--) #define inf 100000000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//***************************************
#define maxn 1000000+5
bool P[maxn];
int k;
int prime[maxn];
vector<int >V;
int H[maxn],S[maxn];
void init()
{
P[]=;
for(int i=;i<=;i++)
{
if(!P[i])
{
for(int j=i+i;j<=;j=j+i)
P[j]=;
}
}
k=;
for(int i=;i<=;i++)
{
if(!P[i])
prime[++k]=i;
}
}
__int64 get( __int64 x,__int64 y)
{
__int64 j=;
while(y<x)
{
x-=y;
j++;
y+=y;
}
if(j==)j++;
return j;
}
int main()
{
int T;
init();
scanf("%d",&T); while(T--)
{
V.clear();
ll n=read();
ll m=read();
if(n==m)
{
printf("0\n");
continue;
}
if(n>m)
{
printf("-1\n");
continue;
}
if(n==)
{
printf("-1\n");
continue;
}
if(m%n){
cout<<-<<endl;
continue;
}
ll tmp=m/n;//cout<<tmp<<endl;
for(int i=;i<=k;i++)
{
while(n%prime[i]==)
{
if(H[prime[i]]==)
V.push_back(prime[i]);
H[prime[i]]++;
n/=prime[i];
}if(prime[i]>n)break;
} // for(int i=0;i<V.size();i++)cout<<V[i]<<endl;
__int64 ans=;
for(int i=;i<V.size();i++)
{
if(tmp%V[i]==) {
ll jj=;
while(tmp%V[i]==)
{
tmp/=V[i];
jj++;
}
ans=max(ans,get(jj,H[V[i]]));
}
H[V[i]]=;
}
if(tmp!=){
printf("-1\n");
}
else printf("%I64d\n",ans); } return ;
}
代码
BestCoder Round #60/HDU 5505 暴力数学的更多相关文章
- Bestcoder round #65 && hdu 5593 ZYB's Tree 树形dp
Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- Bestcoder round #65 && hdu 5592 ZYB's Premutation 线段树
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submissio ...
- [BestCoder Round #3] hdu 4908 BestCoder Sequence (计数)
BestCoder Sequence Problem Description Mr Potato is a coder. Mr Potato is the BestCoder. One night, ...
- [BestCoder Round #3] hdu 4907 Task schedule (模拟简单题)
Task schedule Problem Description 有一台机器,而且给你这台机器的工作表.工作表上有n个任务,机器在ti时间运行第i个任务,1秒就可以完毕1个任务. 有m个询问,每一个 ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...
- HDU 5506 - BestCoder Round #60 - GT and set
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1003 题意 : 给N集 ...
- BestCoder Round #60 题解链接
题解 题目 1001 GT and sequence 注意先特判000的情况:如果读入的数据有000,那么去掉所有的000且最后答案和000取一个max. 剩下的正数显然全部乘起来比较优. 对于负数 ...
- [BestCoder Round #5] hdu 4956 Poor Hanamichi (数学题)
Poor Hanamichi Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- BestCoder Round #60 1002
Problem Description You are given two numbers NNN and MMM. Every step you can get a new NNN in the w ...
随机推荐
- 自定义 Java Annotation ,读取注解值
1. 首先是自定义注解: package cn.veji.hibernate.po; import java.lang.annotation.ElementType; import java.lang ...
- SDK_进度条和滑块
进度条和滑块 进度条和滑块属于通用控件,通用控件的使用需要加 CommCtrl.h 头文件 如何初始化进度条和滑块的数值范围和默认的位置 // 设置默认的范围值SendDlgItemMessage(h ...
- 梦想MxWeb3D,三维CAD协同设计平台 2019.04.09更新
SDK开发包下载地址: http://www.mxdraw.com/ndetail_10140.html 在线演示网址: http://www.mxdraw.com:3000/ 1. 增加上传dwg ...
- 微服务网关从零搭建——(八)Ocelot网关中加入skywalking APM
准备工作 一.下载skywalking 本例使用的是 注: 1.解压后执行完2,3步骤后运行\bin\startup.bat 2.默认后台端口为8080 如需修改则修改\webapp\webapp.y ...
- .Net Core2.2 + EF Core + DI,三层框架项目搭建教程
笔记: 近两年.Net Core发展的很快,目前最新版为3.0预览版,之前在网上买了一本1.1版书籍都还没来得及看呢,估计现在拿出来看也毫无意义了.已多年.net工作经验,看书不如直接实际上手来得快, ...
- <MyBatis>入门一 HelloWorld
1.HelloWorld 导入依赖 <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis --> <dependen ...
- Python学习-while循环练习
1.计算1-100的和 i = 1; total = 0; while i <= 100: total = total + i; i = i + 1; print(total); 2.打印出1- ...
- CCF201409-2 画图 java(100分)
试题编号: 201409-2 试题名称: 画图 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 在一个定义了直角坐标系的纸上,画一个(x1,y1)到(x2,y2)的矩形指将横坐 ...
- 一:安装centos 7最小编程环境 xfce桌面
1, u盘制作安装盘------------------------------------------------------安装时, table或者e进入编辑选项 如果不知道你的u盘的盘符 ...
- python面试题之如何在Python中创建自己的包
Python中创建包是比较方便的,只需要在当前目录建立一个文件夹, 文件夹中包含一个__init__.py文件和若干个模块文件, 其中__init__.py可以是一个空文件,但还是建议将包中所有需要导 ...