Perfect Pth Powers poj1730
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 16383 | Accepted: 3712 |
Description

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& ...
随机推荐
- Python学习日志_2017/09/08
今天早晨学习了<Head First :HTML and CSS>:学习了两个章节,感觉从基础学习特别的踏实,能看懂的同时踏踏实实的锻炼了基础的能力.我个人认为无论哪个行业,最重要的永远是 ...
- bugly cocos 接入和 符号表使用
bugly cocos 接入和 符号表使用 在bugly网站下载 BuglyCocosPlugin 的sdk ios 1. 在 项目的 classes 里面新建 文件夹 BuglyCocosPlug ...
- Mybatis 之级联查询 一对多配置
Mybatis级联 查询相对于hibenate是有点麻烦,但是相应好处也是有的,Mybatis轻量.根据自己要的字段配置方便 一对多配置用 <collection property=&quo ...
- poj 1679 Prim判断次短路
题意:判断最短路是否唯一. 思路:先prrim一次求出最短路同时记录最短路加入的边: 然后枚举所求边,将其删除再求n-1次prim,判断再次所求得的最短路与第一次求得的次短路的关系. 代码: #inc ...
- Mac上好用的视频播放器有哪些?
首页发现话题 提问 登录加入知乎 Mac 上好用的视频播放器有哪些? 关注问题写回答 OS X 应用 多媒体播放器(软件) Mac 上好用的视频播放器有哪些? 关注者 2680 被浏览 981770 ...
- [转载]Linux shell中的竖线(|)——管道符号
原文地址:Linux shell中的竖线(|)--管道符号作者:潇潇 管道符号,是unix一个很强大的功能,符号为一条竖线:"|". 用法: command 1 | command ...
- (2)ES6解构赋值-数组篇
1.解构赋值-数组篇 //Destrcturing(解构) //ES5 /* var a = 1; var b = 2; var c = 3; */ //ES6 var [a,b,c] = [1,2, ...
- 201521123099 《Java程序设计》第八周学习总结
1. 本周学习总结 2. 书面作业 本次作业题集集合 List中指定元素的删除(题目4-1) 1.1 实验总结 老师上课解释的还有私下问同学大概能懂.主要理解到一点在删除List中元素时要考虑元素删除 ...
- 201521123032 《Java程序设计》第3周学习总结
1. 本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点.截图或者拍照上传. 2. 书面作 ...
- windows消息机制与实例
windows发送窗口消息 所需工具:spy++,visual studio 2017,c#语言 技术路线:首先通过spy++获得所要操纵的窗口的句柄,函数的原型声明为: [DllImport(&qu ...