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 ...
随机推荐
- JavaScript一些不常用的写法
如何写JavaScript才能逼格更高呢?怎样才能组织JavaScript才能让别人一眼看出你不简单呢?是否很期待别人在看完你的代码之后感叹一句“原来还可以这样写”呢?下面列出一些在JavaScrip ...
- 一种基于PTP 协议的局域网高精度时钟同步方法(转)
原文地址 http://www.dzsc.com/data/html/2011-1-17/88338.html 1 引言 在分布式系统中, 常常需要一个全局时间, 用来确定系统中各种事件发生的先后.协 ...
- USB Device Finder
http://www.velleman.eu/images/tmp/usbfind.c #ifdef __cplusplus extern "C" { #endif #includ ...
- C#将html导出到word(基于wps)
由于客户需要,我们需要实现将网页导出到word中的功能,在此过程中,尝试使用过openoffice.itext.wordapi等各种方法,都不尽如人意.openoffice导出的问题图片信息在word ...
- Java多线程:线程死锁
发生死锁的原因通常是两个对象的锁相互等待造成的. 以下用一个实例来构造这样的情况: package basic.e_deadlock; import org.apache.log4j.Logger; ...
- AJAX responseText vs responseXML
AJAX------>本质 Request/Response(Server)模式 response的形式 responseText--------->获得字符串形式的响应数据. ----- ...
- Android典型界面设计——ViewPage+Fragment实现区域顶部tab滑动切换
一.问题描写叙述 本系列将结合案例应用,陆续向大家介绍一些Android典型界面的设计,首先说说tab导航,导航分为一层和两层(底部区块+区域内头部导航).主要实现方案有RadioGroup+View ...
- mysql开启慢查询方法(转)
1,配置开启 Linux: 在mysql配置文件my.cnf中增加 log-slow-queries=/var/lib/mysql/slowquery.log (指定日志文件存放位置,可以为空,系统会 ...
- Category目录
Category目录 目录 概述——对Category的理解 创建Category Category的用途 概述——对Category的理解 当我们想往原有的类中添加新的成员方法但又不想改变原有的类和 ...
- data URI scheme
优化网页效能,首要的任务是尽量减少HTTP请求(http request)的次数,例如把多个JavaScript文档合并,多个CSS文件合并等等.此外,还有有一种 data URL 的方法,可以直接把 ...