这个有2种方法。

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

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int fun(double n)
{
int p=,f=;
if(n<)
{
p=;
f=;
n=-n;
}
for(;p>=;p-=f)
{
double a=pow(n,1.0/p);
long t1=a;
long t2=a+;
if(a-t1<=1e-||t2-a<=1e-)
break;
}
return p;
}
int main()
{
int x,p;
while(cin>>x&&x)
{
p=fun(x);
cout<<p<<endl;
}
return ;
}

第二种方法就是分解素数因子,求出因子的指数的最大公约数就是答案了,但是我这测试没错,提交超时……

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int prime[],a[];
void init()
{
int i,j,k=;
for(i=;i<=;i++)
{
if(!a[i])
{
prime[k++]=i;
for(j=i+i;j<=;j+=i)
a[j]=;
}
}
}
int gcd(int a,int b)
{
int c;
if(a<b) swap(a,b);
while(b)
{
c=a;
a=b;
b=c%b;
}
return a;
}
int main()
{
int n,i,j;
bool flag;
init();
while(scanf("%d",&n),n)
{
flag=;
if(n<)
{
flag=;
n=-n;
}
vector<int> key;
for(i=;prime[i]*prime[i]<=n;i++)
{
if(n%prime[i]==)
{
int c=;
for(;n%prime[i]==;n/=prime[i],c++);
key.push_back(c);
}
}
if(n>) key.push_back();
int sum=key[];
for(i=;i<key.size();i++)
sum=gcd(sum,key[i]);
if(flag)
{
while(sum%==)
sum/=;
}
printf("%d\n",sum);
}
return ;
}

poj 1730 Perfect Pth Powers的更多相关文章

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

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

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

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

  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. 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. Android之“Unfortunately,xxx has stopped!”

    初学Android遇到Unfortunately,xxx has stopped!真是一件让人头疼的事情,下面就遇到的两种可能情况给出解决方案.通常遇到的情况在于由一个Activity跳转至另一个Ac ...

  2. line-height属性使文字垂直居中原理

    原理:line-height与font-size的计算之差(在CSS中成为“行间距”)分为两半,分别加到一个文本内容的顶部和底部,这样就使得文字垂直居中了.

  3. selenium+python find_element_by_css_selector方法使用

    1.通过类class获取 比如如下代码 <h1 class="important"> This heading is very important. </h1&g ...

  4. C# Winfrom小黄鸡功能调用

    最近研究微信公众平台,搭建了一个微信聊天机器人,调用小黄鸡的公众接口,实现在线和小黄鸡聊天的功能. 接口调用不是很麻烦,不过是php版本,所以研究了一下C#的功能模块, Winfrom版 后台界面代码 ...

  5. 【转载】Powershell获取世纪互联Office365中所有用户的OWA时区

    get-mailbox -resultsize unlimited | Get-MailboxRegionalConfiguration | select Identity,TimeZone | wh ...

  6. HotSpot Builder Utility安装指南

    系统需求硬件- 一台带有1个以太网卡的电脑(宿主机)- 一个无线路由器 软件- VirtualBox 4.1或更高的版本.下载网址:http://www.virtualbox.org/- 我们提供的最 ...

  7. Windows Phone中的几种集合控件

    前言 Windows Phone开发过程中不可避免的就是和集合数据打交道,如果之前做过WP App的开发的话,相信你已经看过了各种集合控件的使用.扩展和自定义.这些个内容在这篇博客里都没有,那么我们今 ...

  8. 【F#】核心数据多线程处理的首选

    http://www.cnblogs.com/zilin-xiao/archive/2011/08/26/2155124.html

  9. Qt实现指定线程执行回调

    说明 同线程时,直接调用回调(block参数没意义) 创建invoker所在的线程,需要有Qt的消息循环(比如UI线程) 直接上代码 typedef std::function<void()&g ...

  10. 服务器端spice配置详解

    1. 安装必要的工具 sudo apt-get install build-essential autoconf git-core intltool 2. 安装必要的依赖包 -dev libxfixe ...