poj_1730_Perfect Pth Powers
Input
Output
Sample Input
17
1073741824
25
0
Sample Output
1
30
2 一点都不难但是很讨厌的一道题,很烦的地方就是输入可以为负,没有处理搞了半天runtime error。
然后输入用longlong。
对于输入为负的数字。例64=2^6,然而-64=(-4)^3。
综上,负数的output只能为奇数
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#define N 100001
using namespace std;
typedef long long ll;
bool vis[N];
int prime[N];
int pn=0;
int gcd(int a,int b)
{
if(!b) return a;
return gcd(b,a%b);
}
int main()
{
for (int i = 2; i < N; i++) {
if (vis[i]) continue;
prime[pn++] = i;
for (int j = i; j < N; j += i)
vis[j]=1;
}
ll n;
while(~scanf("%lld",&n),n)
{
ll r=n>0?n:-n;
int ans=0;
for(int i=0;(long long)prime[i]*prime[i]<=r;i++)
{
int tem=0;
while(r%prime[i]==0)
{
r/=prime[i];
tem++;
}
if(tem)
ans=gcd(ans,tem);
}
if(r!=1&&ans)
ans=gcd(ans,r);
if(!ans)
ans++;
if(n<0)
{
while(ans%2==0)
ans/=2;
}
cout<<ans<<endl;
}
}
poj_1730_Perfect Pth Powers的更多相关文章
- UVA 10622 - Perfect P-th Powers(数论)
UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...
- Perfect Pth Powers poj1730
Perfect Pth Powers Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16383 Accepted: 37 ...
- poj 1730Perfect Pth Powers(分解质因数)
id=1730">Perfect Pth Powers Time Li ...
- 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, ...
- POJ 1730 Perfect Pth Powers(暴力枚举)
题目链接: https://cn.vjudge.net/problem/POJ-1730 题目描述: We say that x is a perfect square if, for some in ...
- [暑假集训--数论]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 ...
- poj 1730 Perfect Pth Powers
这个有2种方法. 一种是通过枚举p的值(p的范围是从1-32),这样不会超时,再就是注意下精度用1e-8就可以了,还有要注意负数的处理…… #include<iostream> #incl ...
- UVa 10622 (gcd 分解质因数) Perfect P-th Powers
题意: 对于32位有符号整数x,将其写成x = bp的形式,求p可能的最大值. 分析: 将x分解质因数,然后求所有指数的gcd即可. 对于负数还要再处理一下,负数求得的p必须是奇数才行. #inclu ...
- uva10622 Perfect P-th Powers
留坑(p.343) 完全不知道哪里有问题qwq 从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊 #include<cstdio> #include<cstring&g ...
随机推荐
- 07-spring之三大框架的整合
1 三大框架整合理论 2 导包(42个) 1 hibernate 1 hibernate/lib/required 2 hibernate/lib/jpa | java persist api jav ...
- python3.4中自定义wsgi函数,make_server函数报错问题
别的不多说,先上代码 #coding:utf-8 from wsgiref.simple_server import make_server def RunServer(environ, start_ ...
- SpringBoot如何集成Jedis
添加jedis依赖 在项目pom.xml文件中添加依赖 <!-- 添加jedis依赖 --> <dependency> <groupId>redis.clients ...
- golang中并发的相关知识
golang中done channel理解:https://segmentfault.com/a/1190000006261218 golang并发模型之使用Context:https://segme ...
- C#入门--字段与属性
C#入门--字段与属性 “字段”,它是包含在类或结构中的对象或值.字段使类和结构可以封装数据. 属性是这样的成员:它们提供灵活的机制来读取.编写或计算私有字段的值.可以像使用公共数据成员一样使用属性, ...
- spring注入bean的五种方式
1.属性注入 2.构造方法注入 3.静态工厂注入 package com.voole.factorybeans; import com.voole.beans.TestBean; public cla ...
- C#中关于静态与非静态的一个疑问
关于静态方法.变量和非静态方法.变量的区别,园里的大神早就有了许多详细的总结,个人觉得静态方法.变量与非静态方法.变量的区别可以总结为以下两句话: 静态的是属于类的 非静态是属于对象的 就是说调用静态 ...
- libmysqlclient.so.16未找到方法
用mysql命令登录的时候报错: [root@iZ www]# mysql -uroot -p mysql: error while loading shared libraries: libmysq ...
- git 获取领先落后的命令
git --git-dir=/data/usr/local/gerrit-site/git/aixuexi-admin.git rev-list --left-right --count master ...
- 易客CRM-3.0.4 (OpenLogic CentOS 6.5)
平台: CentOS 类型: 虚拟机镜像 软件包: apache1.3.8 centos6.5 mysql5.1.72 php5.2.17 commercial crm linux 服务优惠价: 按服 ...