hdu-5505(数论)
题目链接:
GT and numbers
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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 <bits/stdc++.h> #include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef unsigned long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e6+;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
}
int prime[N];
struct node
{
int a[],m;
}po[N];
void Init()
{
for(int i=;i<N;i++)
{
po[i].m=;
}
for(int i=;i<N;i++)
{
if(!prime[i])
{
po[i].a[po[i].m++]=i;
for(int j=*i;j<N;j+=i)
{
po[j].a[po[j].m++]=i;
prime[j]=;
}
}
}
}
LL check(int x)
{
LL s=;
for(int i=;i<=x;i++)
{
s*=;
}
return s;
}
int getans(int x,int y)
{
int l=,r=(int)(log(y/x+)/log(2.0))+;
while(l<=r)
{
int mid=(l+r)>>;
if(check(mid)*x>=y)r=mid-;
else l=mid+;
}
return r+;
}
void solve(int n,LL m)
{
if(n==)
{
if(m==)printf("0\n");
else printf("-1\n");
}
else
{
int ans=;
int tempn=n;
LL tempm=m;
for(int i=;i<po[n].m;i++)
{
int num1=;
while(tempn%po[n].a[i]==)
{
tempn/=po[n].a[i];
num1++;
}
int num2=;
while(tempm%po[n].a[i]==)
{
tempm/=po[n].a[i];
num2++;
}
if(num2<num1)
{
printf("-1\n");
return ;
}
ans=max(ans,getans(num1,num2));
}
if(tempm>)printf("-1\n");
else printf("%d\n",ans);
}
}
int main()
{
Init();
int T;
scanf("%d",&T);
int n;
LL m;
while(T--)
{
read(n);
scanf("%I64u",&m);
solve(n,m);
}
return ;
}
hdu-5505(数论)的更多相关文章
- hdu 5505(数论-gcd的应用)
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- HDU 5505 - BestCoder Round #60 - GT and numbers
题目链接 : http://bestcoder.hdu.edu.cn/contests/contest_chineseproblem.php?cid=641&pid=1002 思路 : N有若 ...
- hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...
- hdu 4961 数论?
http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; ...
- hdu 1664(数论+同余搜索+记录路径)
Different Digits Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3641 数论 二分求符合条件的最小值数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...
- hdu 4059 数论+高次方求和+容斥原理
http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...
- hdu 5505 GT and numbers
GT and numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
随机推荐
- 同时使用Binding&StringFormat 显示Text【项目】
Case ID (?unit) 红色的字根据一个后台boolean来做trigger,可以是Case or Open 蓝色的字binding到后台的一个string属性来切换任意的Unit单位 这样一 ...
- ActiveMQ的消息确认问题
http://riddickbryant.iteye.com/blog/441890 [发送端] session = connection.createSession(Boolean.FALSE, ...
- 全代码实现ios-4
刚开始开发的时候,也曾经想用IB或Storyboard. 不过看了许多篇关于IB和Storyboard的操作文档后仍然是糊里糊涂,不由得怀疑自己的IQ. 可不可以全代码实现ios开发?当时我想. 不过 ...
- Delphi Data Types
http://docwiki.embarcadero.com/RADStudio/XE6/en/Delphi_Data_Types Integer Data Types Type Descriptio ...
- c++课程实训 银行储蓄系统
基本要求:定义了用户类(User)和银行类(Bank),用成员函数实现各种功能,多文件组织程序.能用文本文件存取数据(如演示样例中给出的技术): 拓展方向: 序号 加分项目 细 则 1 改 ...
- Delphi Data Type to C# Data Type
Delphi DataType C# datatype ansistring string boolean bool byte byte char char comp double currency ...
- 【M34】如何在同一个程序中结合C++和C
1.C++和C混合编程的时候,需要考虑产生的目标文件的兼容性. 2.名称重整,为什么要搞出名称重整? 连接器要求所有方法名必须独一无二.对于C语言,没问题.C++支持过载,也就是方法名相同,形参表不同 ...
- linux下的文件操作——批量重命名
概述:在日常工作中,我们经常需要对一批文件进行重命名操作,例如将所有的jpg文件改成bnp,将名字中的1改成one,等等.文本主要为你讲解如何实现这些操作 1.删除所有的 .bak 后缀: renam ...
- Codeforces Round #264 (Div. 2) C
题目: C. Gargari and Bishops time limit per test 3 seconds memory limit per test 256 megabytes input s ...
- HtmlAgilityPack.dll的使用 获取HTMLid
简介 本文介绍net处理html页面元素的工具类(HtmlAgilityPack.dll)的使用,用途比较多的应该是例如采集类的功能,采集到的html字符串要怎样处理是一个头痛的问题,如果是截取就太麻 ...