We say that x is a perfect square if, for some integer b, x = b 2. Similarly, x is a perfect cube if, for some integer b, x = b 3. More generally, x is a perfect pth power if, for some integer b, x = b p. Given an integer x you are to determine the largest p such that x is a perfect p th power.

Input

Each test case is given by a line of input containing x. The value of x will have magnitude at least 2 and be within the range of a (32-bit) int in C, C++, and Java. A line containing 0 follows the last test case.

Output

For each test case, output a line giving the largest integer p such that x is a perfect p th power.

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的更多相关文章

  1. poj1730 - Perfect Pth Powers(完全平方数)(水题)

    /* 以前做的一道水题,再做精度控制又出了错///... */ 题目大意: 求最大完全平方数,一个数b(不超过int范围),n=b^p,使得给定n,p最大: 题目给你一个数n,求p : 解题思路: 不 ...

  2. UVA 10622 - Perfect P-th Powers(数论)

    UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...

  3. Perfect Pth Powers poj1730

    Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16383   Accepted: 37 ...

  4. POJ 1730 Perfect Pth Powers(暴力枚举)

    题目链接: https://cn.vjudge.net/problem/POJ-1730 题目描述: We say that x is a perfect square if, for some in ...

  5. 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, ...

  6. [暑假集训--数论]poj1365 Prime Land

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

  7. poj 1730 Perfect Pth Powers

    这个有2种方法. 一种是通过枚举p的值(p的范围是从1-32),这样不会超时,再就是注意下精度用1e-8就可以了,还有要注意负数的处理…… #include<iostream> #incl ...

  8. UVa 10622 (gcd 分解质因数) Perfect P-th Powers

    题意: 对于32位有符号整数x,将其写成x = bp的形式,求p可能的最大值. 分析: 将x分解质因数,然后求所有指数的gcd即可. 对于负数还要再处理一下,负数求得的p必须是奇数才行. #inclu ...

  9. uva10622 Perfect P-th Powers

    留坑(p.343) 完全不知道哪里有问题qwq 从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊 #include<cstdio> #include<cstring&g ...

随机推荐

  1. java常用 开源

    http://sourceforge.nethttp://code.google.com/hosting/http://www.open-open.com/code/tags/Javahttp://w ...

  2. MySQL 5.7 在线启用和关闭GTID

    1.相关基础 MySQL 5.7.6之后GTID_MODE提供了两个新的选项分别为ON_PERMISSIVE和OFF_PERMISSIVEOFF_PERMISSIVE:不产生GTID事务, Slave ...

  3. iOS开发——应用间跳转

    iOS开发过程中,我们经常碰到应用间跳转的情景: 1.使用第三方用户登录,跳转到需授权的App或跳转到分享app的对应页面 *需要用户授权,还需要"返回到调用的程序,同时返回授权的用户名.密 ...

  4. .NET中变量生存期

    Web窗体后台 cs 文件中,创建类作用域的变量,在关闭页面的时候并不会消失,当 IIS 站点被关闭的时候,才会调用这个变量的析构函数 但是好像也不肯定在关闭站点才会析构,应该是外层对象析构的时候才会 ...

  5. Oracle - 存储过程、函数、包的使用练习-雇员

    --存储过程范例:得到雇员表 emp 的记录数 begin --说明:若过程中要向外抛异常,请使用 exception when others then raise; 这个抛出的异常在程序里是可以捕获 ...

  6. webpack+thymeleaf实现数据直出

    webpack动态插入thymeleaf模板,MVC将要使用数据传递到模板中渲染,得到的html就已经带有要初始显示的数据了github:https://github.com/947133297/we ...

  7. 在基于vue-cli的项目自定义打包环境

    在工作当中,遇到了下面这个问题: 测试环境与生产环境中的用户权限不一样,因此,就需要根据测试环境打一个包,生产环境又打一个包.可是,如果每次打包都需要更改权限的配置文件的话,会很麻烦,而且,体现不出一 ...

  8. html下拉菜单栏代码

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. SoapUI(一)之webservice测试

    webservice测试需要具备的条件: 1.了解业务需求:如从客户端发送一个post请求给服务器,服务器将响应传给客户端. 2.需要一个明确的wsdl地址: 如天气预报的接口链接:http://ww ...

  10. 单片机入门学习笔记6:新唐单片机N76E003

    学习新唐单片机是从2018年3月开始的,之前一点也不懂这一块单片机,之后脉络变的越来越清晰. 由于N76E003档次太低,新塘科技官方的管脚配置,芯片选型……都没有这一块芯片,资料唯独只有:芯片的数据 ...