UESTC 1246 拆x3
2015-11-29 12:57
302 查看
用归纳法分析可以知道死循环只有4。
分析一下复杂度,如果n很大并且不是素数,根据基本不等式可以知道 sum factor(n) ≥ 2+n/2 ≈ n/2。
复杂度是O(T*logN*sqrt(N)),这个上界比较松。如果是用Pollard_rho再开个平方估计常数也差不多了。
分析一下复杂度,如果n很大并且不是素数,根据基本不等式可以知道 sum factor(n) ≥ 2+n/2 ≈ n/2。
复杂度是O(T*logN*sqrt(N)),这个上界比较松。如果是用Pollard_rho再开个平方估计常数也差不多了。
#include<bits/stdc++.h> using namespace std; typedef long long ll; int decompose(int x, bool &is_pm) { int re = 0; for(int i = 2; i*i <= x; i++){ while(x % i == 0){ re += i; x /= i; } } is_pm = !re; if(x > 1) { re += x; } return re; } //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt","r",stdin); #endif int x, y; bool is_pm; while(~scanf("%d", &x)){ if(x == 4) puts("-1"); else { while(true){ y = decompose(x, is_pm); if(is_pm) break; x = y; } printf("%d\n", x); } } return 0; }
相关文章推荐
- [LeetCode]Count Univalue Subtrees
- UIView的常用方法及相关属性
- UIColor 常用方法
- 蓝牙HC-05与Arduino Pro mini实现蓝牙防远离
- UIImageJPEGRepresentation和UIImagePNGRepresentation使用区别
- 兔子-(PHP 5.3 and above) Please set 'request_order' ini value to include C,G and P (recommended: 'CGP'
- Longest Consecutive Sequence
- POJ1458 Common Subsequence LCS模板题
- 高性能MYSQL读书要点摘录_2_性能刨析工具_pt-query-digest
- Git可视化极简易教程 —— Git GUI使用方法
- postgresql downgrade issue
- uiautomator支持中文输入详细教程
- [LeetCode308]Range Sum Query 2D - Mutable
- 模板:HDU 1242: Rescue: (BFS DFS)
- [LeetCode298]Binary Tree Longest Consecutive Sequence
- requirejs源码
- Codeforces Round #333 (Div. 1)--B. Lipshitz Sequence 单调栈
- 【UI进阶】关于IB的理解,不知道这样是否可以
- 1017. Queueing at Bank (25)——PAT (Advanced Level) Practise
- 【UI进阶】IB(Interface Builder)的一点小总结