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. 企业服务的3种模式:On-Premise、SaaS、Mixed,该选哪种?--创业邦

    B轮融资二三事 我们从9月份开始启动B轮融资,与这些颇具洞察力的投资人聊天,是非常有挑战的事.他们的很多观点充满智慧,能帮你突破思考局限,受益良多.当然,整个过程虽然有趣但也不轻松,毕竟你的目的是完成 ...

  2. OC开发_Storyboard——多线程、UIScrollView

    一.多线程 1.主队列:处理多点触控和所有UI操作(不能阻塞.主要同步更新UI) dispatch_queue_t mainQueue = dispatchg_get_main_queue(); // ...

  3. C++中的const的用法

    const对象.指向const对象的指针.const指针(通过一个面试题来了解)   1.const对象 (1)关于const,很多企业的笔试.面试都会出现,很简单,就问你“const的含义?”. 我 ...

  4. SQL Server 存储过程生成流水号

    SQL Server利用存储过程生成流水号 USE BiddingConfig SET QUOTED_IDENTIFIER ON SET ANSI_NULLS ON GO -- =========== ...

  5. 解决“The remote certificate is invalid according to the validation procedure”问题

    在用HttpClient发起https请求时,遭遇了“The remote certificate is invalid according to the validation procedure”异 ...

  6. Linux系统stat指令用法

    stat指令:文件/文件系统的详细信息显示. stat命令主要用于显示文件或文件系统的详细信息,该命令的语法格式如下: stat命令-->用来显示文件的详细信息,包括inode, atime, ...

  7. linux内核cdev_init系列函数(字符设备的注册)

    内核中每个字符设备都对应一个 cdev 结构的变量,下面是它的定义: linux-2.6.22/include/linux/cdev.h struct cdev {    struct kobject ...

  8. 内核通信之Netlink源码分析-用户内核通信原理3

    2017-07-06 上节主讲了用户层通过netlink和内核交互的详细过程,本节分析下用户层接收数据的过程…… 有了之前基础知识的介绍,用户层接收数据只涉及到一个核心调用readmsg(), 其他的 ...

  9. MySQL的知识海洋

    第一篇:初识数据库 第二篇:库操作 第三篇:表操作 第四篇:数据操作 第五篇:视图.触发器.存储过程.函数.事物与数据库锁 第六篇:索引原理与慢查询优化 第七篇:pymysql(用python连接以及 ...

  10. 整合最优雅SSM框架:SpringMVC + Spring + MyBatis 基础

    在写代码之前我们先了解一下这三个框架分别是干什么的? 相信大以前也看过不少这些概念,我这就用大白话来讲,如果之前有了解过可以跳过这一大段,直接看代码! SpringMVC:它用于web层,相当于con ...