http://poj.org/problem?id=1730

题意:
给出一个n,a=b^p,求出最大p值。

思路:

首先利用唯一分解定理,把n写成若干个素数相乘的形势。接下来对于每个指数求最大公约数,该公约数就是所能到达的最大p值。

有一点要注意的是如果n为负数的话,如果当前p值为偶数,就一直除2直到p为奇数。

 #include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
using namespace std; const int maxn = ; long long n;
int vis[maxn];
int prime[];
int cnt; void get_prime()
{
cnt = ;
int m = sqrt(maxn + 0.5);
for (int i = ; i < maxn; i++)
{
if (!vis[i])
{
prime[cnt++] = i;
for (int j = i; j < maxn; j += i)
vis[j] = ;
}
}
} int gcd(int a, int b)
{
if (a < b) return gcd(b, a);
if (b == ) return a;
return gcd(b, a % b);
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
get_prime();
while (~scanf("%lld", &n) && n)
{
int flag = ;
int ans = ;
if (n < )
{
n = -n;
flag = ;
}
int flag2 = ;
for (int i = ; i < cnt && n>; i++)
{
if (n%prime[i] == )
{
int ret = ;
while (n%prime[i] == )
{
n /= prime[i];
ret++;
}
ans = gcd(ans, ret);
}
}
if (n > ) ans = ;
if (flag)
{
while (ans % == ) ans /= ;
}
printf("%d\n", ans);
}
}

POJ 1730 Perfect Pth Powers(唯一分解定理)的更多相关文章

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

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

  2. poj 1730 Perfect Pth Powers

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

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

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

  4. Perfect Pth Powers poj1730

    Perfect Pth Powers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16383   Accepted: 37 ...

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

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

  7. POJ 1845 Sumdiv (整数唯一分解定理)

    题目链接 Sumdiv Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 25841   Accepted: 6382 Desc ...

  8. UVa 10622 (gcd 分解质因数) Perfect P-th Powers

    题意: 对于32位有符号整数x,将其写成x = bp的形式,求p可能的最大值. 分析: 将x分解质因数,然后求所有指数的gcd即可. 对于负数还要再处理一下,负数求得的p必须是奇数才行. #inclu ...

  9. uva10622 Perfect P-th Powers

    留坑(p.343) 完全不知道哪里有问题qwq 从31向下开始枚举p,二分找存在性,或者数学函数什么的也兹辞啊 #include<cstdio> #include<cstring&g ...

随机推荐

  1. 关于OS命令注入的闭合问题

    1.在Windows下 windows下非常好办,只需要&肯定可以执行: C:\Users\xxx\Desktop>aaaa | 127.0.0.1 'aaaa' 不是内部或外部命令,也 ...

  2. IIS 无法访问.net的动态文件

    编译器错误消息:CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319... 在“c:\windows\temp”这个文件夹添 ...

  3. sql语句查询条件的不同表达方式对查询性能的影响

    今天操作数据库遇到一个问题 目标表RA_AD_DAILY_DATA的数据量大概有5千万左右,其中的BUSINESS_DATE字段为日期类型 我要查询8月20号导入的三条记录,刚开始用这种方式去查: S ...

  4. nodejs 事件EventEmitter

    index.js: // 引入 events 模块 var events = require('events'); //处理函数要写在调用前 var eventHandler = function() ...

  5. 【Android】Android--Dialog

    前言 对话框对于应用也是必不可少的一个组件,在Android中也不例外,对话框对于一些提示重要信息,或者一些需要用户额外交互的一些内容很有帮助.本篇博客就讲解一下Android下对话框的使用,在本篇博 ...

  6. 最短路和次短路的条数(dijstra算法或spfa算法)POJ3463

    http://poj.org/problem?id=3463 Sightseeing Time Limit: 2000MS   Memory Limit: 65536K Total Submissio ...

  7. hdu4975 网络流解方程组(网络流+dfs判环或矩阵DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4975 A simple Gaussian elimination problem. Time Limit: 20 ...

  8. Jenkins构建时提示maven版本问题

    在使用Jenkins进行项目构建的时候出现下面问题 [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were enc ...

  9. Centos7更改yum源与更新系统

    [1] 首先备份 /etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/Cen ...

  10. Google Now 'not available in your country'

    Google Now 'not available in your country' Don't know how to cope with this problem.