[暑假集训--数论]poj1730 Perfect Pth Powers
Input
Output
Sample Input
17
1073741824
25
0
Sample Output
1
30
2
给个n,把它表示成a^b的形式,问b最大是多少,n有负数
正数简单,负数要打个标记,最后答案b要除到没有2的因子为止
比如-1073741824=-(2^30)=(-4)^15,但是不能是(-2)^30
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
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;
}
LL n;
bool mk[];
int p[],len;
inline LL LLabs(LL a){return a<?-a:a;}
inline void getp()
{
for (int i=;i<=;i++)
{
if (!mk[i])
{
p[++len]=i;
for (int j=*i;j<=;j+=i)mk[j]=;
}
}
}
inline void work()
{
int flag=(n<),ans=;n=LLabs(n);
for (int i=;i<=len;i++)
{
if ((LL)p[i]*p[i]>n)break;
if (n%p[i]!=)continue;
int now=;while (n%p[i]==)n/=p[i],now++;
if (!ans)ans=now;else ans=__gcd(ans,now);
}
if (n!=)ans=;
if (flag)while (ans%==)ans/=;
printf("%d\n",ans);
}
int main()
{
getp();
while (~scanf("%lld",&n)&&n)work();
}
poj 1730
[暑假集训--数论]poj1730 Perfect Pth Powers的更多相关文章
- poj1730 - Perfect Pth Powers(完全平方数)(水题)
/* 以前做的一道水题,再做精度控制又出了错///... */ 题目大意: 求最大完全平方数,一个数b(不超过int范围),n=b^p,使得给定n,p最大: 题目给你一个数n,求p : 解题思路: 不 ...
- UVA 10622 - Perfect P-th Powers(数论)
UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...
- Perfect Pth Powers poj1730
Perfect Pth Powers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16383 Accepted: 37 ...
- POJ 1730 Perfect Pth Powers(暴力枚举)
题目链接: https://cn.vjudge.net/problem/POJ-1730 题目描述: We say that x is a perfect square if, for some in ...
- Kattis之旅——Perfect Pth Powers
We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, ...
- [暑假集训--数论]poj1365 Prime Land
Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...
- poj 1730 Perfect Pth Powers
这个有2种方法. 一种是通过枚举p的值(p的范围是从1-32),这样不会超时,再就是注意下精度用1e-8就可以了,还有要注意负数的处理…… #include<iostream> #incl ...
- UVa 10622 (gcd 分解质因数) Perfect P-th Powers
题意: 对于32位有符号整数x,将其写成x = bp的形式,求p可能的最大值. 分析: 将x分解质因数,然后求所有指数的gcd即可. 对于负数还要再处理一下,负数求得的p必须是奇数才行. #inclu ...
- uva10622 Perfect P-th Powers
留坑(p.343) 完全不知道哪里有问题qwq 从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊 #include<cstdio> #include<cstring&g ...
随机推荐
- hadoop install
1.home下建立hadoop 2.在Downloads下解压hadoop-2.6.0.tar.gz 3.将解压后的hadoop-2.6.0移动到/home/hadoop 4.csf@ubuntu:/ ...
- Drop it-freecodecamp算法题目
Drop it 1.要求 丢弃数组(arr)的元素,从左边开始,直到回调函数return true就停止. 第二个参数,func,是一个函数.用来测试数组的第一个元素,如果返回fasle,就从数组中抛 ...
- bat 服务启动脚本
当电脑上有多个数据库(特别是Oracle,占用内存大,所以我都是设置为手动启动的,或者想在电脑上运行一下其他UI类软件或玩些游戏的时候也需要暂时关掉,奈何我这渣机(V_V))需要启动或停止的时候,就用 ...
- django+xadmin在线教育平台(四)
3-2 配置表单页面 必要的该说的,该了解的 前置条件: 你已经学习了前面教程.将项目的文件夹目录结构,setting配置等修改完毕与我保持一致. 本节通过Django快速的配置一个留言板页面来学习 ...
- http 实战练习
http 实战练习 建立httpd服务器,要求提供两个基于名称的虚拟主机: (1)www.X.com,页面文件目录为/web/vhosts/x:错误日志为/var/log/httpd/x.err,访问 ...
- JZOJ 3388. 【NOIP2013模拟】绿豆蛙的归宿
3388. [NOIP2013模拟]绿豆蛙的归宿 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limi ...
- 循环(while、for)
写重复的代码是程序员最不耻的行为,那么如何做到不用写重复代码又能让程序重复一段代码多次呢,循环语句就派上用场拉…… 一.while 循环 # while 语法结构 while 条件: 执行代码.... ...
- BZOJ 4971: [Lydsy1708月赛]记忆中的背包
神仙构造 分成x个1和一堆>=w-x的大物品 (x<=20 w>=50) 则拼成w的方案中有且仅有一个大物品 若最终序列中有x个1,有一个大物品为w-k,可以提供C(x,k)种方案 ...
- Android 有些机型hint不显示
这个问题就是有些手机型号,hint字体正好和你的背景色一样,不如你的背景色是白色, 因为大多数的系统,hint都是灰色,所以可以显示,有些手机他妈的就是hint默认字体是白色,结果显示不出来. 那么就 ...
- Python+selenium(警告框处理)
在Webdriver中处理JavaScript生成的alert.confirm.prompt,使用switch_to_alert()方法定位到alert.confirm.prompt,然后进行如下操作 ...