题目链接:点我


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

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.

Output

For each case, print the case number and the largest integer p such that x is a perfect pth power.

Sample Input

317107374182425

Sample Output

Case 1: 1Case 2: 30Case 3: 2

题意:

给你一个公式 x=bpx = b ^{p}, 给你一个数x,求最大的p.

思路:

唯一分解定理:x = pe11p_1^{e_1} * pe22p_2^{e_2} *pe33p_3^{e_3} ….,那么根据题意所有ans = gcd( e1e_1 ,e2e_2,e3e_3…….);而且这里,如果x为负数的话,那么ans一定只能是奇数.
代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;typedef long long LL;
const int maxn = 1e6 + 10;
bool vis[maxn];
int pri[maxn/10];
int k , num = 0;
LL n, ans;
bool flag;
LL a[1000];void prime(){memset(vis,false,sizeof(vis));for(int i = 2; i < maxn; ++i){if (!vis[i]) pri[++num] = i;for(int j = 1;j <= num && i *pri[j] < maxn; ++j){vis[i * pri[j]] = true;if (i % pri[j] == 0) break;}}
}LL gcd(LL a, LL b){return b ? gcd(b, a % b) : a;
}void solve(){for(int i = 1; i <= num && pri[i] <= (int)sqrt(n); ++i){int cnt = 0;while(n % pri[i] == 0){++cnt;n /= pri[i];}if(cnt) a[++k] = cnt;if (cnt == 1){ans = 1;return ;}} if(n > 1) {ans = 1;return ;}int tmp = a[1];for(int i = 2; i <= k; ++i){tmp = gcd( tmp, a[i]);}if(flag){//如果n为奇数,那么ans 只能为奇数,while(tmp % 2 ==0)tmp /= 2;}ans = tmp;
}int main(){int t, kase = 0;prime();scanf("%d", &t);while( t--){scanf("%lld", &n);flag = false;if(n < 0){flag = true;n = -n;}k = 0;ans = 0;solve();printf("Case %d: %lld\n", ++kase, ans);}return 0;
}

LightOJ 1220 Mysterious Bacteria相关推荐

  1. LightOJ 1220 Mysterious Bacteria(唯一分解定理) (素数筛)

    题干: 给你一个整数x,令x= b p b^p bp(b,p都为整数),求p的最大值. x为32位有符号整型. 思路: 首先,素数因为不能被除1和它自身外整除,所以x为素数时p=1: x为合数时,根据 ...

  2. Mysterious Bacteria(唯一分解定理)

    Mysterious Bacteria(唯一分解定理) Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 ...

  3. Mysterious Bacteria LightOJ - 1220[唯一分解定理+思维题]

    题目大意:就是给你一个数n问这个数是什么数的整数幂,输出这个幂指数,如果有多个输出幂指数最大的那个 就是对于一个数n=p1a1∗p2a2∗...∗pxaxn=p_1^{a_1}*p_2^{a_2}*. ...

  4. LightOJ-1220 Mysterious Bacteria (素数打表+欧几里得算法+唯一分解定理)给出x,求x=a^p,最大的指数

    题目大意: x = b^p, x只有一个因子的p次幂构成 如果24 = 2^3*3^1,p应该是gcd(3, 1) = 1,即24 = 24^1 324 = 3^4*2^2=(3^2*2)^2,p应该 ...

  5. Mysterious Bacteria(唯一质因子解+素数筛)

    原题目: Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 has a very strange rep ...

  6. Mysterious Bacteria 唯一分解定理+素数筛

    题目大意: 给你一个数x = b^p,求p的最大值 x = p1^x1*p2^x2*p3^x3*...*ps^xs 开始我以为是找x1.x2.... .xs中的最大值,后来发现想错了,x = b^p, ...

  7. kuangbin带你飞专题合集

    题目列表 [kuangbin带你飞]专题一 简单搜索 [kuangbin带你飞]专题二 搜索进阶 [kuangbin带你飞]专题三 Dancing Links [kuangbin带你飞]专题四 最短路 ...

  8. 算法学习经典例题整理

    陆续会对本篇博客进行更新! 搜索:https://vjudge.net/contest/292597 区间DP:https://vjudge.net/contest/293892 树状背包:https ...

  9. kuangbin带你飞 专题1-23 题单

    kuangbin大神,对于打过ACM比赛的ACMer,无人不知无人不晓. 在此,附上vjudge平台上一位大神整理的[kuangbin带你飞]专题目录链接. [kuangbin带你飞专题目录1-23] ...

最新文章

  1. 使用IsLine FrameWork开发ASP.NET程序之一——命名空间与契约概览
  2. 实探全球第九大超算中心:温水冷却节能30% 正寻求新突破
  3. 数据库语法_圣诞快乐:用GaussDB T 绘制一颗圣诞树,兼论高斯数据库语法兼容...
  4. 【入门2】分支结构 (今天刷洛谷了嘛)
  5. BZOJ 1036: [ZJOI2008]树的统计Count
  6. iPhone 12主板曝光:布局更紧凑 满满苹果基因
  7. vscode设置templates_Vscode中快速创建自定义代码模板的方法
  8. 北京-波士顿-西雅图时间对照表
  9. 使用Docker Swarm来运行服务
  10. Louvain社区划分算法及Java语言实现
  11. python3解密栅栏密码的正确方法
  12. G002-186-17
  13. 【附源码】计算机毕业设计java音乐鉴赏网站前端开发设计与实现
  14. R语言ggplot2可视化格式化轴标签:用逗号格式化ggplot2轴标签、在轴标签数值中加入符号标签(货币符号)
  15. CCF小白刷题之路---201809-1 卖菜(C/C++ 100分)
  16. ML之XGBoost:《XGBoost: A Scalable Tree Boosting System》的翻译与解读
  17. 在线教育学习平台网校系统v2020 html5响应式在线教育培训类企业使用+安装说明
  18. Flex——项目item的属性(order、flex-grow、flex-shrink、flex-basis、flex、align-self)
  19. 2013腾讯马拉松编程初赛3月23日1001
  20. MySQL数据库的MNA集群环境配置

热门文章

  1. java程序员进阶必读书单
  2. sqlserver/mysql 替换部分位置的字符串
  3. 罐装红酒的开拓者——智利菲尔帝进军中国市场
  4. matlab中矩阵的表示与简单操作
  5. 三菱触摸屏通讯错误_三菱触摸屏插上通讯线直接黑屏,老司机手把手教你解决触摸屏黑屏...
  6. D3 天眼查 股权穿透 股权结构
  7. suse12搭建ntp服务器
  8. ERROR: Cannot uninstall 'PyYAML'. It is a distutils installed project and thus we cannot accurately
  9. echarts的series配置
  10. SSH建立连接的过程