LightOJ1220 Mysterious Bacteria
来源:互联网 发布:软件质量保证什么阶段 编辑:程序博客网 时间:2024/06/10 17:18
题目链接:点我
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 =
代码:
#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;}
阅读全文
0 0
- LightOJ1220 Mysterious Bacteria
- LightOJ1220 Mysterious Bacteria(思维+唯一分解)
- Mysterious Bacteria
- Mysterious Bacteria
- lightOJ 1220 Mysterious Bacteria
- LightOj Mysterious Bacteria
- LightOJ 1220 Mysterious Bacteria
- (LightOJ 1220)Mysterious Bacteria
- LightOJ 1220 Mysterious Bacteria
- LightOJ 1220 Mysterious Bacteria
- LightOJ 1220 Mysterious Bacteria
- lightOJ 1220 Mysterious Bacteria
- Mysterious Bacteria LightOJ
- lightOJ 1220 Mysterious Bacteria
- lightoj 1220 - Mysterious Bacteria 【数学】
- lightoj 1220 - Mysterious Bacteria 【数学】
- light oj 1220 Mysterious Bacteria
- Mysterious Bacteria ( lightOJ 1220)
- mysql的安装和常见问题
- C++和python中将程序内的绝对路径转为相对路径
- 简单抓站的N种方式-lxml与xpath
- 关于第一次套上shiro框架遇到的页面css等失效现象
- iOS给label设置click事件
- LightOJ1220 Mysterious Bacteria
- 本地开发spark代码上传spark集群服务并运行
- NYOJ2括号配对问题( 栈的应用)
- 汇编open file
- POJ 2251 Dungeon Master
- Android查看应用方法数-65536限制
- Redis的基本命令
- STM32-PWM输出
- 向上转型向下转型