博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Mysterious Bacteria LightOJ - 1220
阅读量:4550 次
发布时间:2019-06-08

本文共 1099 字,大约阅读时间需要 3 分钟。

题意:

给出一个数x 求 x = bp  的p的最大值

解析:

算术基本定理 分解质因数

任何一个数x都可以表示为  x == p1a1  *  p2a2  *  ````` * pnan

 即  bp  ==  p1a1   *  p2a2  *  ````` * pnan  == (p1b1 * p2b2 * `````` * pnbn)p

所以  pmax  == gcd(a1,a2,·····,an);

如果x是一个负数  则p只能为奇数

先把x换成正数求出最大p之后 如果x 为负 则不断除2 直至p为奇数

代码如下:

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MOD 2018#define LL long long#define ULL unsigned long long#define maxn 1000100#define Pair pair
#define mem(a, b) memset(a, b, sizeof(a))#define _ ios_base::sync_with_stdio(0),cin.tie(0)//freopen("1.txt", "r", stdin);using namespace std;const int LL_INF = 0x7fffffffffffffff,INF = 0x3f3f3f3f;int primes[maxn];bool vis[maxn];int ans = 0;LL gcd(LL a, LL b){ return b==0?a:gcd(b,a%b);}void init(){ mem(vis,0); for(int i=2; i
0) { if(res == 0) res = cnt2; res = gcd(res, cnt2); } } if(n > 1) { res = 1; } if(flag) { while(res % 2 == 0) res /= 2; } printf("Case %d: %d\n",++kase,res); } return 0;}

 

转载于:https://www.cnblogs.com/WTSRUVF/p/9190087.html

你可能感兴趣的文章
比较:I/O成员函数getline() 与 get()(第二种用法)的用法异同
查看>>
201671010118 2016-2017-2《Java程序设计》 第十一周学习心得
查看>>
Get Sauce(状压DP)
查看>>
Office2007 升级到 office2010
查看>>
Python+Selenium 自动化实现实例-Xpath捕捉元素的几种方法
查看>>
SpringBoot整合Hibernate
查看>>
PPT1 例2
查看>>
extern外部方法使用C#简单例子
查看>>
血液循环结构
查看>>
SQL Server统计数据库中表个数、视图个数、存储过程个数
查看>>
设计模式:观察者模式
查看>>
JVM体系结构之六:堆Heap之1
查看>>
TCP之二:TCP的三次握手与四次分手
查看>>
es的返回数据结构
查看>>
[ActionScript 3.0] as3处理xml的功能和遍历节点
查看>>
linux学习(6)-redhat安装xwindow环境
查看>>
6.28 加法作业
查看>>
CentOS6+nginx+uwsgi+mysql+django1.6.6+python2.6.6
查看>>
【bzoj2829】信用卡凸包 凸包
查看>>
oracle 游标
查看>>