题目链接:

https://cn.vjudge.net/problem/POJ-1730

题目描述:

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
 /*
题意描述
输入x,计算并输出满足x=b的p次方中最大的p 解题思路
因为x的大小为2到2的31次方,故可采取枚举次方的方法,计算出b,再计算出b的p次方为temp,看temp和x是否相等即可。
另外需要注意的是x可能为负数,首先需要将负数变为正数,另外枚举的时候只能枚举奇数次方,因为偶数次方不能的到负数。
另外是用pow开方和乘方时注意精度问题,比如4.999999直接取整误差很大,加上0.1即可避免此类问题。
*/
#include<cstdio>
#include<cmath> int main()
{
int x;
while(scanf("%d",&x),x != ){
if(x > ){
for(int i=;i>=;i--){
int b=(int)(pow(x*1.0,1.0/(i*1.0)) + 0.1);
int temp=(int)(pow(b*1.0,i*1.0) + 0.1);
if(x == temp){
printf("%d\n",i);
break;
}
}
}
else{
x *= -;
for(int i=;i>=;i-=){
int b=(int)(pow(x*1.0,1.0/(i*1.0)) + 0.1);
int temp=(int)(pow(b*1.0,i*1.0) + 0.1);
if(x == temp){
printf("%d\n",i);
break;
}
}
}
}
return ;
}

POJ 1730 Perfect Pth Powers(暴力枚举)的更多相关文章

  1. POJ 1730 Perfect Pth Powers(唯一分解定理)

    http://poj.org/problem?id=1730 题意:给出一个n,a=b^p,求出最大p值. 思路: 首先利用唯一分解定理,把n写成若干个素数相乘的形势.接下来对于每个指数求最大公约数, ...

  2. poj 1730 Perfect Pth Powers

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

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

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

  4. Perfect Pth Powers poj1730

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

  5. [暑假集训--数论]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 ...

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

  7. POJ 3279 - Fliptile - [状压+暴力枚举]

    题目链接:http://poj.org/problem?id=3279 Sample Input 4 4 1 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 Sample Output 0 ...

  8. uva10622 Perfect P-th Powers

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

  9. POJ 1380 Equipment Box (暴力枚举)

    Equipment Box 题目链接: http://acm.hust.edu.cn/vjudge/contest/130510#problem/B Description There is a la ...

随机推荐

  1. Java学习--基本数据类型的定义和运算

    例1: public class DataDemo05{ public static void main(String args[]){ char ch1 = '\"' ; // 表示的是一 ...

  2. PhantomJS快速入门-无界面浏览器

    https://blog.csdn.net/libsyc/article/details/78199850 PhantomJS快速入门 本文简要介绍了PhantomJS的相关基础知识点,主要包括Pha ...

  3. 在 Ubuntu 16.04上安装 vsFTPd

    在 Ubuntu 16.04上安装 vsFTPd Ubuntu vsFTPd 关于 vsFTPd vsFTPd 代表 Very Secure File Transfer Protocol Daemon ...

  4. C# 一些代码小结--UI操作

    C# 一些代码小结--UI操作 使用控件名调用控件 object obj = this.GetType().GetField("控件名", System.Reflection.Bi ...

  5. [面试题目]IT面试中的一些基础问题

    1. 面向对象的特征 继承,封装,多态 2. 重写和重载的区别 重写:在继承当中,子类重写父类的函数,函数声明完全一样,只是函数里面的操作不一样,这样叫做重写. 重载:与多态无关,即两个函数名一样的成 ...

  6. 【洛谷4587】 [FJOI2016]神秘数(主席树)

    传送门 BZOJ 然而是权限题 洛谷 Solution 发现题目给出的一些规律,emm,如果我们新凑出来的一个数,那么后面一个数一定是\(sum+1\). 于是就可以主席树随便维护了! 代码实现 #i ...

  7. 通过javascript 直接播放amr格式的语言

    前段时间做了个功能(有2.3个月了,突然想起来了,就记录一下),语言播放.一开始觉得很简单~~~ 计划应用的是H5的audio标签,但因为这个标签不支持amr格式的语言,但是手机端传到后台的录音却都是 ...

  8. Windows安装python3.x后,pip list警告!DEPRECATION: The default format will switch to columns in the future.

    前言(凑字数专用) 这个警告虽然不影响你的正常使用,但是每次都好几行红色警告,总是给人一种怪怪的感觉(当然不是FBI的警告了……),所以咱们还是把他解决掉~ 网上好多解决办法都是Ubuntu的解决办法 ...

  9. Linux巩固记录(8) Hbase shell 基本使用

    继续前几篇内容,讲解hbase基本使用 1.进入hbase shell: hbase有很多种操作方式,比如shell,java客户端,webUI等,可以直接输入hbase进行提示 [root@mast ...

  10. 01-Python的基础知识2

    - Python变量 - 变量就是重复使用的一个量,或者一个代号. - 变量的命名规则: - 必须以下划线或者字母开头,后面接任意数量下划线.字母.或数字. - 4man , 5for 是不可以的 - ...