Perfect Pth Powers解题报告

原创 2012年03月30日 08:34:41

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<stdio.h>
#include<math.h>
int main()
{
	double n,b;
	long x,y;
	int i;
	while(scanf("%lf",&n)!=EOF)
	{
		if(n==0)
			break;
		if(n>0)
		{
			for(i=32;i>=0;i--)
			{
				b=pow(n,1.0/i);
				x=b;    //类型转换为long
				y=x+1;  //
				if(b-x<=1e-12||y-b<=1e-12)
				{
					printf("%d\n",i);
					break;
				}
			}
		}
		if(n<0)
		{
			n=-n;  //if n《0,先转化为正数先,然后i 只能为奇数,查找i。
			for(i=31;i>=1;i-=2)
			{
				b=pow(n,1.0/i);
				x=b;      //类型转换为long。
				y=x+1;    //
				if(b-x<=1e-12||y-b<=1e-12)
				{
					printf("%d\n",i);
					break;
				}
			}
		}
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

J - Perfect Pth Powers解题报告

J - Perfect Pth Powers Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d ...

POJ 1730 Perfect Pth Powers 解题报告(因式分解)

Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 1634...
  • kbdwo
  • kbdwo
  • 2014-04-21 15:52
  • 724

J - Perfect Pth Powers解题报告(张宇)

J - Perfect Pth Powers Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d ...

J - Perfect Pth Powers解题报告(陈渊)

J - Perfect Pth Powers Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d ...

poj 1730Perfect Pth Powers(分解质因数)

Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16746   Accep...

poj 1730 Perfect Pth Powers

题目大概意思 给你一个x 令 x=b^p 求最大的p 例如 81=9^2=3^4则p的值为 4 一看蒙啦,这怎么求啊,数据范围在2^32次方之内,纠结,这种题一定会有算法, 再看列出几个...

poj-1730 Perfect Pth Powers

题目链接:http://poj.org/problem?id=1730 Perfect Pth Powers Time Limit: 1000MS   Memory L...

poj-1730 Perfect Pth Powers

J - Perfect Pth Powers Crawling in process...Crawling failedTime Limit:1000MS    Memory Limit:10...

UVaOJ-11752-The Super Powers 解题报告

不错的思考题,可找规律。人生第一次真正意义上的写证明。题意:如果一个数是两个不同的数的幂,那么这个数就称之为超级幂,比如64 = 8^2 = 4^3。因此64是一个超级幂。没有输入,请输出0到2^64...

poj 1730 Perfect Pth Powers 筛法

poj 1730 Perfect Pth Powers 筛法 We say that x is a perfect square if, for some integer b, x = b2. Sim...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)