LightOJ 1220 - Mysterious Bacteria 【数论 - 预处理】
2017-12-12 22:05
489 查看
1220 - Mysterious Bacteria
Time Limit: 0.5 second(s) Memory Limit: 32 MBDr. 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
317
1073741824
25
Output for Sample Input
Case 1: 1Case 2: 30
Case 3: 2
题意: 给你一个int范围内的数为n,问你写成 n=bp成立的情况下,p的最大取值
分析: 看清范围 -> int范围,包括负数和零,一开始根号的复杂度可以求出所有的质因数,但是考虑负数情况很多,懒得讨论,所以直接预处理了所有的数,因为int嘛,很小,但要考虑下特殊情况,这里边界很重要,一定要初始化下,还有就是当n == 0 或者是 1,-1时, 理论是无穷大,这里考虑为1,然后只需要选出最大幂数的即可
参考代码
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<pair<ll,int> > s; const int INF_MAX = 0x7fffffff,INF_MIN = 0x80000000; void init() { ll MIN = INF_MIN; ll MAX = INF_MAX; for(ll i = -50000;i <= 50000;i++) { if(i == -1 || i == 0 || i == 1) { s.push_back(make_pair(i,1)); continue; } ll t = 1; for(int j = 1;j < 33;j++) { t *= i; if(t <= MAX && t >= MIN) { s.push_back(make_pair(t,j)); } } } } int main() { init(); int T;cin>>T; for(int t = 1;t <= T;t++) { ll n;cin>>n; if(n == 0) { printf("Case %d: %d\n",t,1); continue; } int res = 1; bool flg = false; for(int i = 0;i < s.size();i++) { if(n == s[i].first) { flg = true; res = max(res,s[i].second); } } printf("Case %d: %d\n",t,res); } return 0; }
附: 几组样例需要的可以拿走
Input 13 17 1073741824 25 2147483647 -2147483648 32 -32 64 -64 4 -4 324 -46656 Output Case 1: 1 Case 2: 30 Case 3: 2 Case 4: 1 Case 5: 31 Case 6: 5 Case 7: 5 Case 8: 6 Case 9: 3 Case 10: 2 Case 11: 1 Case 12: 2 Case 13: 3 Input 7 -16 16 64 -64 15 17 36 Output Case 1: 1 Case 2: 4 Case 3: 6 Case 4: 3 Case 5: 1 Case 6: 1 Case 7: 2 Input 10 -1048576 -16777216 1048576 16777216 1024 1023 101 121 2 3 Output Case 1: 5 Case 2: 3 Case 3: 20 Case 4: 24 Case 5: 10 Case 6: 1 Case 7: 1 Case 8: 2 Case 9: 1 Case 10: 1
如有错误或遗漏,请私聊下UP,thx
相关文章推荐
- LightOJ 1035 Intelligent Factorial Factorization [预处理+一半的 质因子分解]【数论】
- LightOj 1220 Mysterious Bacteria(数论)
- Mysterious Bacteria ( lightOJ 1220)
- lightOJ 1278 Sum of Consecutive Integers(数论,数学推导)
- LightOJ - 1282E - Leading and Trailing(数论)
- LightOJ 1220 Mysterious Bacteria(唯一分解定理+暴力)
- lightoj Basic Math 数论基础题 1414+1010+1020+1078+1116+1148+1179+1214+1275+1294+1297+1311+1323+1349+1354
- LightOJ 1045 - Digits of Factorial 简单数论
- LightOJ 1245 (数论:找规律)
- LightOJ 1259 Goldbach`s Conjecture(数论)
- LightOJ - 1220
- LightOJ 1220 - Mysterious Bacteria(唯一分解定理)
- 数论知识点1——快速幂取模-LightOJ 1282
- 【LightOJ】1331 - Agent J(数论)
- LightOJ -kuangbin 数论
- 【LightOJ1259】Goldbach`s Conjecture(数论)
- LightOJ 1220 Mysterious Bacteria
- lightoj 1429 - Assassin`s Creed (II) 【BFS预处理传递闭包 + SCC缩点 + DAG最小路径覆盖】
- LightOJ-1259 Goldbach`s Conjecture 数论 素数筛
- LightOJ - 1220(n=b^k时最大的k,GCD)