[暑假集训--数论]poj1730 Perfect Pth Powers
Input
Output
Sample Input
17
1073741824
25
0
Sample Output
1
30
2
给个n,把它表示成a^b的形式,问b最大是多少,n有负数
正数简单,负数要打个标记,最后答案b要除到没有2的因子为止
比如-1073741824=-(2^30)=(-4)^15,但是不能是(-2)^30
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
LL n;
bool mk[];
int p[],len;
inline LL LLabs(LL a){return a<?-a:a;}
inline void getp()
{
for (int i=;i<=;i++)
{
if (!mk[i])
{
p[++len]=i;
for (int j=*i;j<=;j+=i)mk[j]=;
}
}
}
inline void work()
{
int flag=(n<),ans=;n=LLabs(n);
for (int i=;i<=len;i++)
{
if ((LL)p[i]*p[i]>n)break;
if (n%p[i]!=)continue;
int now=;while (n%p[i]==)n/=p[i],now++;
if (!ans)ans=now;else ans=__gcd(ans,now);
}
if (n!=)ans=;
if (flag)while (ans%==)ans/=;
printf("%d\n",ans);
}
int main()
{
getp();
while (~scanf("%lld",&n)&&n)work();
}
poj 1730
[暑假集训--数论]poj1730 Perfect Pth Powers的更多相关文章
- poj1730 - Perfect Pth Powers(完全平方数)(水题)
/* 以前做的一道水题,再做精度控制又出了错///... */ 题目大意: 求最大完全平方数,一个数b(不超过int范围),n=b^p,使得给定n,p最大: 题目给你一个数n,求p : 解题思路: 不 ...
- 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 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, ...
- [暑假集训--数论]poj1365 Prime Land
Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...
- 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 ...
随机推荐
- GCH文件
GCH文件是将H文件当作CPP进行编译之后出现的结果, 在头文件进行编译后就会在文件夹中看到一个 “文件名.h.gch” 的文件. 那么在再次对gch文件进行编译的时候就会将gch当作cpp一样对待. ...
- Load事件中控件Focus()无效解决办法
原因:Load窗体时,窗体未显示 解决:1.Focus()之前添加this.Show(); 2.在Shown事件中添加Focus()
- swift 循环语句
// // main.swift // switch // // Created by lanou on 16/10/21. // Copyright (c) 2016年 lanou. All rig ...
- (79)zabbix key总是not supported的解决方法
zabbix定义好key之后,总是会出现Not supported,看到这个问题,大家不用着急,问题其实很容易解决,首先鼠标点击当前key的大红叉上,会显示出报错内容. 常见的有: 1. zabbix ...
- django+xadmin在线教育平台(三)
通过留言版功能回顾django基础知识 将对于django目录结构,使用Django快速搭建可以提交的表单页面,models.py , urls.py, views.py. 从数据库中取出数据展示到h ...
- 第2 章Python 语言基础
必背必记 1.转义字符 Python 中的字符串还支持转义字符.所谓转义字符是指使用反斜杠“\”对一些特殊字符进行转义. \ 续行符 \n 换行符 \0 空 \t 水平制表符,用于横向跳到下一制表 ...
- 如何禁止js缓存?
<html> <head> <script type="text/javascript"> document.write("<s ...
- php中 为什么验证码 必须要开启 ob_clean 才可以显示
用ob_clean(),将前面的输出都清除就OK了 这表示你的程序前面有输出,<?php 前有空格.空行.文件有BOM头 ob_clean(); header("content-typ ...
- Pychram基本操作
1. 更改pychram页面为黑色背景主题.更改主题: File ->Settings -> Editor -> Color Scheme -> Scheme -> Mo ...
- Ubuntu samba 安装与配置 实现windows和虚拟机中的Ubuntu共享文件
2. 安装sumba服务 sudo apt-get install samba samba-common 这里出现了小问题, Ubuntu上安装samba不能安装的问题,“下列的软件包有不能满足 ...