Mysterious Bacteria 素因子分解(唯一分解定理)
来源:互联网 发布:潘多拉优化中心 编辑:程序博客网 时间:2024/06/07 01:10
题意:(题目在最后)
给你一个整数n,让你求满足b^p=x的最大的p,例如72=2^3*3^2;结果是1;因为只有72^1=72;
216=2^3*3^3=6^3,结果是3;
利用 唯一分解定理x=p1^e1*p2^e2*......pi^ei,存下每一个指数,再求最大公约数,得到答案;
注意:两个点
1: n有可能是负的,这时候先把n变成正数求,因为只有b^奇数才可能为负数,(n=-4时,-2^2=4,显然不可能=n)
所以要把所有的指数不断除2转化成奇数(n=-64时,-2^6=(-2^2)^3=-4^3,结果是3)
2:素数打表用long long ,不然平方时会炸。
#include<cstdio>#include<cstring>using namespace std;typedef long long ll;const int N=100005;int tot=0,d,a[100];ll ans[N/10];bool vis[N];void Prime(){ memset(vis,true,sizeof(vis)); for(int i=2;i<N;i++) { if(vis[i]) ans[++tot]=i; for(int j=1;(j<=tot)&&(i*ans[j]<N);j++) { vis[i*ans[j]]=false; if(i%ans[j]==0) break; } }}int gcd(int a,int b) { return b?gcd(b,a%b):a;}void sbreak(ll x){ d=0; memset(a,0,sizeof(a)); for(int i=1;ans[i]*ans[i]<=x;i++) { int cnt=0; if(x%ans[i]==0) d++; while(x%ans[i]==0) { x/=ans[i]; a[d]=++cnt; } } if(x>1) {d=1;a[1]=1;}}int main(){ Prime(); int t,cas=0; scanf("%d",&t); while(t--) { ll x; bool tag=false; scanf("%lld",&x); if(x<0) {x=-x;tag=true;} sbreak(x); int t=a[1]; if(tag) { for(int i=1;i<=d;i++) { while(a[i]%2==0) a[i]/=2; t=gcd(t,a[i]); } } else for(int i=1;i<=d;i++) t=gcd(t,a[i]); printf("Case %d: %d\n",++cas,t); } return 0;}
Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 has a very strange reproduction system. RC-01 lives exactly x days. Now RC-01 produces exactly p new deadly Bacteria where x = bp (where b, p are integers). More generally, x is a perfect pth power. Given the lifetime x of a mother RC-01 you are to determine the maximum number of new RC-01 which can be produced by the mother RC-01.
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a line containing an integer x. You can assume that x will have magnitude at least 2 and be within the range of a 32 bit signed integer.
For each case, print the case number and the largest integer p such that x is a perfect pth power.
3
17
1073741824
25
Case 1: 1
Case 2: 30
Case 3: 2
- Mysterious Bacteria 素因子分解(唯一分解定理)
- LightOJ 1220 - Mysterious Bacteria(唯一分解定理)
- LightOJ 1220 Mysterious Bacteria(唯一分解定理+暴力)
- Mysterious Bacteria (素数筛法+唯一分解定理+gcd | |暴力)
- LightOJ 1220 - Mysterious Bacteria (质因子分解)
- 分解素因子----唯一分解定理
- LightOJ1220 Mysterious Bacteria(思维+唯一分解)
- 阶乘质因子分解(唯一分解定理)
- NYOJ 476 谁是英雄(唯一素因子分解定理)
- 质因数分解(唯一分解定理)
- 质因数分解(唯一分解定理)
- Professor Ben 唯一分解定理:因子的因子个数
- uva10375(唯一分解定理)
- 唯一分解定理(数论)
- UVa10375(唯一分解定理)
- uva10375(唯一分解定理)
- uva10791(唯一分解定理)
- 算数基本定理(唯一分解定理)
- MUI框架默认全局不可复制
- 线段树_初步
- stm32串口发送16进制字符和16进制数的区别和具体实现方法
- 阿里Druid
- 仿IOS效果-ToggleButton
- Mysterious Bacteria 素因子分解(唯一分解定理)
- 关于回调注销问题的总结
- dp-基础3 B
- 每日一题(44)—— 请列举一个软件中时间换空间或者空间换时间的例子
- <Linux> 使用ssh,ngrok 外网远程连接linux(树莓派)
- RMAN正确地删除Archivelog以及设置有备库的归档删除策略
- Mybatis之使用注解开发CRUD
- java,字符串定义和初始化,new String[5],为什么错误和正确?
- Spring MVC框架环境的搭建