TOJ 1438.Perfect Pth Powers
来源:互联网 发布:西安鼓楼网络售票 编辑:程序博客网 时间:2024/05/17 10:26
题目链接:http://acm.tju.edu.cn/toj/showp1438.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 2341 Accepted Runs: 466
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.
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.
For each test case, output a line giving the largest integer p such that x is a perfect pth power.
Sample Input
171073741824250
Output for Sample Input
1302
Source: Waterloo Local Contest Jan. 31, 2004
水题,直接用pow就好,注意n的范围。
#include <stdio.h>#include <cmath>using namespace std;int main(){long long n;while(~scanf("%lld",&n),n){if(n>0){for(int i=31;i>0;i--){double p=pow(1.0*n,1.0/i);for(long long j=p-10;j<=p+10;j++)if( (long long)pow(1.0*j,i)==n){printf("%d\n",i);i=0;break;}}}else {n=-n;for(int i=31;i>0;i-=2){double p=pow(1.0*n,1.0/i);for(long long j=p-10;j<=p+10;j++)if( (long long)pow(1.0*j,i)==n){printf("%d\n",i);i=0;break;}}}}}
0 0
- TOJ 1438.Perfect Pth Powers
- poj1730 - Perfect Pth Powers
- Perfect Pth Powers
- Perfect Pth Powers(ZJU_2124)
- ZJU 2124 Perfect Pth Powers
- POJ 1730 Perfect Pth Powers
- poj 1730 -- Perfect Pth Powers
- poj 1730 Perfect Pth Powers
- zoj 2124 Perfect Pth Powers
- poj 1730 Perfect Pth Powers
- PKU 1730 Perfect Pth Powers
- poj-1730 Perfect Pth Powers
- poj-1730 Perfect Pth Powers
- Perfect Pth Powers解题报告
- poj 1730 Perfect Pth Powers
- ZOJ 2124 Perfect Pth Powers
- POJ-1730-Perfect Pth Powers
- 【数论】poj1730 Perfect Pth Powers
- 模拟实现trim方法
- 1016. Phone Bills (25)-PAT甲级真题
- 【Consul】Consul实践指导-Encryption配置
- 两学一做
- 字符串池和堆
- TOJ 1438.Perfect Pth Powers
- 823oracle
- ReactNative设置 Image容器的 圆角背景
- 【lightoj1294】数学
- python多线程
- 几种硬盘IO性能测试工具
- AndroidCallPhone
- 数据结构实验之排序四:寻找大富翁
- Rocketmq 消息的解压缩