[暑假集训--数论]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 ...
随机推荐
- python换行
python中如果一行代码太长,看着不方便时,怎么办? 只需要在需要换行的地方添加上符号 \ 就行了.
- mysql基础,DISTINCT关键字
- Linux问题分析或解决_samba无法连接
1. windows设置方面问题 问题:window能连接部分服务器的samba共享,一部分无法连接.报错如截图. 解决:前提---其他人连接都没有问题,发现有问题的连接服务器的电脑是win10,而w ...
- Fakeapp 入门教程(3):参数篇
参数可以让软件自由度更高.Fakeapp的参数并不算多,但是也非常使用.本文就讲解下几个重要的参数.参数设置界面可以通过点击SETTINGS打开. 参数修改无需点击保存,一旦修改直接生效. Proce ...
- 20181225 基于TCP/IP和基于UDP/IP的套接字编程
一.TCP/IP的套接字编程 服务器端代码: import socketserver = socket.socket() # 默认是基于TCP# 基于TCP的对象serve=socket.sock ...
- C++学习网站——www.cplusplus.com
http://www.cplusplus.com/ 有各个函数.语法的实例代码,可以在线运行http://cpp.sh/不支持中文字符,不错.
- linux下编译openjdk8
一.准备工作 1.0 工作环境 Ubuntu 12.04,32位机 1.1.安装JD ...
- C# datagridview列绑定类中类的属性
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://www.cnblogs.com/linghaoxinpian/p/5906374. ...
- 云容器和安全性仍然是困扰IT人士的头号问题
[TechTarget中国原创] 容器和云安全仍然是IT领域中最热门的两个话题.下面就让我们来详细探讨一下吧. 云容器风靡一时是事出有因的.如Docker这样的容器能够提高应用的可移植性,并让企业用户 ...
- HBase官方文档
HBase官方文档 目录 序 1. 入门 1.1. 介绍 1.2. 快速开始 2. Apache HBase (TM)配置 2.1. 基础条件 2.2. HBase 运行模式: 独立和分布式 2.3. ...