Perfect Pth Powers poj1730
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 16383 | Accepted: 3712 |
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
Output
Sample Input
17
1073741824
25
0
Sample Output
1
30
2
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#define MAXN 100010
#define INF 0x7fffffff
using namespace std;
const int N = ;
int np[N >> ], p[N >> ],ans[N]= {};
void init()
{
int n = N;
p[] = , p[] = ;
for (int i = ; i <= n; i++, i++)
{
if (np[i >> ] & ( << ((i >> ) & ))) continue;
p[++p[]] = i;
for (int j = (i << ) + i; j <= n; j += (i << ))
{
np[j >> ] |= ( << ((j >> ) & ));
}
}
}
int gcd(int x,int y)
{
if(y==)return x;
return gcd(y,x%y);
}
int fun(long long x)
{
int i,ans=,an=;
bool flag=;
if(x<)flag=,x=-x;;
for(i=; x>=p[i]&&i<=p[]; i++)
{
if(x%p[i]==)
{
ans=;
while(x%p[i]==)ans++,x/=p[i];
if(an==)an=ans;
else
{
an=gcd(ans,an);
}
}
}
if(x!=)
{
an=;
}
while(flag&&(an%==))an>>=;
if(an==)return ;
return an;
}
int main()
{
init();
long long n;
while(~scanf("%I64d",&n),n)
{
printf("%d\n",fun(n));
}
}
Perfect Pth Powers poj1730的更多相关文章
- UVA 10622 - Perfect P-th Powers(数论)
UVA 10622 - Perfect P-th Powers 题目链接 题意:求n转化为b^p最大的p值 思路:对n分解质因子,然后取全部质因子个数的gcd就是答案,可是这题有个坑啊.就是输入的能够 ...
- [暑假集训--数论]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(暴力枚举)
题目链接: https://cn.vjudge.net/problem/POJ-1730 题目描述: We say that x is a perfect square if, for some in ...
- 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, ...
- poj1730 - Perfect Pth Powers(完全平方数)(水题)
/* 以前做的一道水题,再做精度控制又出了错///... */ 题目大意: 求最大完全平方数,一个数b(不超过int范围),n=b^p,使得给定n,p最大: 题目给你一个数n,求p : 解题思路: 不 ...
- 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 ...
- UVA 10622 Perfect P-th Powers
https://vjudge.net/problem/UVA-10622 将n分解质因数,指数的gcd就是答案 如果n是负数,将答案除2至奇数 原理:(a*b)^p=a^p*b^p #include& ...
随机推荐
- ubuntu 14.04中安装phpmyadmin即mysql图形管理界面
由于学习的需要,我将网站开发环境从windows转移到了ubuntu,ubuntu下之前并没有发现什么难的地方,只要百度一般都有解决方案.但是总所周知ubuntu是一系列开源软件的集合,由于版本的问题 ...
- Junit单元测试实例
1.非注解 public class Test { @org.junit.Test public void testPrice() { ClassPathXmlApplicationContext b ...
- Zookeeper的安装的配置
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt192 安装和配置详解 本文介绍的 Zookeeper 是以 3.2.2 这个 ...
- 如何用比较快速的方法掌握Spring的核心——依赖注入,Java web轻量级开发面试教程 读书笔记
我们知道,Java方面的高级程序员一定得掌握Spring的技能,其中包括Spring 依赖注入(IOC),面向切面(AOP),和数据库的整合(比如和Hibernate整合或声明式事务等)以及Sprin ...
- PowerShell: 问题,此系统上禁止运行脚本解决方法
刚学Django,在PowerShell上建立一个虚拟环境,准备激活,问题来了: 激活的时候报错了,有点儿懵,之前在命令行没问题啊,我又去命令行试了下,果然可以: 感受到了暴击,赶紧上网求助大神 ...
- Project 4:Longest Ordered Subsequence
Problem description A numeric sequence of ai is ordered if a1 < a2 < - < aN. Let the subseq ...
- tomcat配置单项HTTPS协议
1.进入到jdk下的bin目录 1)进入cmd窗口,cd进入目录: 2)找到JDK安装bin目录,shift+右击打开命令窗口: 3)如果配置类环境变量,在任意cmd命令窗口都可以: 2.输入 ...
- NOPI读xls文件写到txt中(NPOI系列二)
private void button2_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); //找 ...
- 自制tunnel口建虚拟专网实验
R1: interface Tunnel12 ip address 192.168.12.1 255.255.255.0 ip ospf 1 area 0 tunnel source 123.123. ...
- CCNA基础知识摘录
cisco设备的启动要点: 1.检测硬件(保存在rom) 2.载入软件(IOS)(保存在Flash) 3.调入配置文件(密码,IP地址,路由协议都保存在此)(此文件保存在NVRAM) 0x2102:正 ...