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

Description

We say that x is a perfect square if, for some integer b, x = b2. Similarly, x is a perfect cube if, for some integer b, x = b3. More generally, x is a perfect pth power if, for some integer b, x = bp. Given an integer x you are to determine the largest p such that x is a perfect pth 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 pth power.

Sample Input

17
1073741824
25
0

Sample Output

1
30
2
 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#define MAXN 100010
#define INF 0x7fffffff
using namespace std;
const int N = ;
int np[N >> ], p[N >> ],ans[N]= {};
void init()
{
int n = N;
p[] = , p[] = ;
for (int i = ; i <= n; i++, i++)
{
if (np[i >> ] & ( << ((i >> ) & ))) continue;
p[++p[]] = i;
for (int j = (i << ) + i; j <= n; j += (i << ))
{
np[j >> ] |= ( << ((j >> ) & ));
}
}
}
int gcd(int x,int y)
{
if(y==)return x;
return gcd(y,x%y);
}
int fun(long long x)
{
int i,ans=,an=;
bool flag=;
if(x<)flag=,x=-x;;
for(i=; x>=p[i]&&i<=p[]; i++)
{
if(x%p[i]==)
{
ans=;
while(x%p[i]==)ans++,x/=p[i];
if(an==)an=ans;
else
{
an=gcd(ans,an);
}
}
}
if(x!=)
{
an=;
}
while(flag&&(an%==))an>>=;
if(an==)return ;
return an;
}
int main()
{
init();
long long n;
while(~scanf("%I64d",&n),n)
{
printf("%d\n",fun(n));
}
}

Perfect Pth Powers poj1730的更多相关文章

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

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

  2. [暑假集训--数论]poj1730 Perfect Pth Powers

    We say that x is a perfect square if, for some integer b, x = b 2. Similarly, x is a perfect cube if ...

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

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

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

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

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

  6. poj 1730 Perfect Pth Powers

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

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

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

  8. uva10622 Perfect P-th Powers

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

  9. UVA 10622 Perfect P-th Powers

    https://vjudge.net/problem/UVA-10622 将n分解质因数,指数的gcd就是答案 如果n是负数,将答案除2至奇数 原理:(a*b)^p=a^p*b^p #include& ...

随机推荐

  1. 基于dijkstra算法求地铁站最短路径以及打印出所有的路径

    拓展dijkstra算法,实现利用vector存储多条路径: #include <iostream> #include <vector> #include <stack& ...

  2. Statement和PrepareStatement区别

    网上很多都说区别是PrepareStatement可以批处理.实际上二者都是可以进行批处理的. 区别在于: 1.PrepareStatement要求预编译的sql必须是格式固定,使用占位符获取参数. ...

  3. window的设置属性

    1.windowAnimationStyle 用于设置一组window动画的引用style资源,window的动画属性由R.styleable.WindowAnimation定义. Winow动画类属 ...

  4. ASP.NET Core 运行原理解剖[5]:Authentication

    在现代应用程序中,认证已不再是简单的将用户凭证保存在浏览器中,而要适应多种场景,如App,WebAPI,第三方登录等等.在 ASP.NET 4.x 时代的Windows认证和Forms认证已无法满足现 ...

  5. 安卓两个build.gradle的区别

    作为安卓入门选手,在导入第三方的时候才发现居然有两个build.gradle,我说咋不对啊,原来是导错了(可能是因为我没有看安卓培训的视频吧). 那么就说一下这两个的作用(一个Project的,一个M ...

  6. linux使用bbswitch+nvidia-xrun取代bumblebee

    nvidia-xrun的比bumblebee使用nvidia optimus的性能更好,关键是xrun支持Vulkan. 本文保存并更新在github:levinit/itnotes/linux/ar ...

  7. 使用设置sa用户登录sql server2008

    今天在net项目中添加数据库过程中出现了小问题,就是使用sql server身份验证没登录成功,经过一番调试,终于解决问题. 使用sa账户登录sql server 2008 的方法步骤如下: 1.首先 ...

  8. 聊一聊我们都熟知的 “ Java分层 ”

    一.为什么要分层. 以前的我们,写代码的时候,都在main()方法中,出现了错误,就慢慢调试,这样浪费了我们很长的时间,而我们程序员的时间是非常宝贵的 但是当我们使用分层架构的时候,就可以清晰明确的知 ...

  9. 201521123078 《Java程序设计》 第8周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 1.List中指定元素的删除(题目4-1) 1.1 实验总结 public static vo ...

  10. 201521123069 《Java程序设计》 第10周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结异常与多线程相关内容. (1)我们可以利用堆栈追踪来获得异常发生的根源(堆栈追踪信息最顶层). (2)自定义异常:不是由Java系统 ...