Perfect Pth Powers
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

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 pth power.

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的更多相关文章

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

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

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

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

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

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

  5. poj1730 - Perfect Pth Powers(完全平方数)(水题)

    /* 以前做的一道水题,再做精度控制又出了错///... */ 题目大意: 求最大完全平方数,一个数b(不超过int范围),n=b^p,使得给定n,p最大: 题目给你一个数n,求p : 解题思路: 不 ...

  6. poj 1730 Perfect Pth Powers

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

  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. 九天学会Java,第五天,函数定义函数调用

    变量和数据类型,赋值和输出 算术运算 选择结构 循环结构 函数定义,函数调用 变量作用域 栈,程序运行的基石 面向对象 异常处理 语言提供的公用包 什么是函数,为什么有函数,大家可能有这样的疑问. 举 ...

  2. 学习js函数--函数定义

    函数的定义方法有三种 1.函数表达式 2.函数声明 3,new function构造函数 这边主要看下函数表达式和函数声明 函数表达式(未省略标志的) var alertName = function ...

  3. mac 终端常用目录跳转命令

    以前一直都是使用Windows系统,连命令行都没怎么用过.来到了Mac,在某位大神的诱导下,我开始尝试使用Mac Terminal,下面总结的是一些简单的目录跳转命令  (菜鸟级) .  文件目录 首 ...

  4. Jquery的入门学习

    jQuery API中文文档地址 http://www.jquery123.com/ Jquery w3school教程 http://www.w3school.com.cn/jquery/index ...

  5. C# xml增删查改

    C# XML XmlDocument 添加命名空间: using System.Xml; 定义公共对象: XmlDocument xmldoc ; XmlNode xmlnode ; XmlEleme ...

  6. 在数组a中,a[i]+a[j]=a[k],求a[k]的最大值,a[k]max——猎八哥fly

    在数组a中,a[i]+a[j]=a[k],求a[k]的最大值,a[k]max. 思路:将a中的数组两两相加,组成一个新的数组.并将新的数组和a数组进行sort排序.然后将a数组从大到小与新数组比较,如 ...

  7. 团队作业1——团队展示&博客作业查重系统

    团队展示: 1.队名:六个核桃 2.队员学号: 王婧(201421123065).柯怡芳(201421123067组长).陈艺菡(201421123068). 钱惠(201421123071).尼玛( ...

  8. 【beta】阶段 第六次 Scrum Meeting

    每日任务 1.本次会议为第六次 Meeting会议: 2.本次会议在周六上午大课间,在陆大楼召开,召开本次会议为15分钟. 一.今日站立式会议照片 二.每个人的工作 (有work item 的ID) ...

  9. 第二次项目冲刺(Beta阶段)--第五天

    一.站立式会议照片 二.项目燃尽图 三.项目进展 - 今天任务是改进程序使程序能完成docx文件的读取,但是并没有成功实现解决该问题,所以燃尽图没有前进. -遇到的问题:不支持docx最早认为是jar ...

  10. 201521123073 《Java程序设计》第5周学习总结

    1. 本周学习总结 2. 书面作业 1.代码阅读:Child压缩包内源代码 1.1 com.parent包中Child.java文件能否编译通过?哪句会出现错误?试改正该错误.并分析输出结果. 1.2 ...