uva 10791
来源:互联网 发布:怎么查看手机端口号 编辑:程序博客网 时间:2024/06/04 20:00
参考紫书:先贴一个唯一分解定理的公式:N=P1a1P2a2P3a3......Pnan。
题意:给一个数n,求出一些数,他们的最小公倍数为n(至少两个数)。
那么根据唯一分解定理,这些数就是P1a1P2a2P3a3......Pnan。
因为这些数是互质的,所以他们就是n的最小的因子们。
求因子的时候最多有一个因子大于floor(sqrt(n) + 0.5)。如果有两个他们的乘积不是比n还大了吗?-_-
/*ID: DickensToneLANG: C++PROB: palsquare*/#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#include<cmath>using namespace std;const int maxn = 33;int div_num(int &n, int f){ int x = 1; while(n % f == 0) {n = n / f; x *= f;} return x;}void to_get(int n){ int cnt = 0, t = n; long long ans = 0; int m = floor(sqrt(n) + 0.5); for(int i = 2; i <= m; i++) { if(n % i == 0) { cnt++; ans += div_num(n, i); //printf("%d\n", ans); } } // printf("%d\n", cnt); if(n > 1) {ans = ans + n; cnt++;} if(cnt <= 1) ans = t + 1LL; printf("%lld\n", ans);}int main(){ //freopen("palsquare.in","r",stdin); //freopen("palsquare.out","w",stdout); int n; int kase = 1; while(scanf("%d", &n) == 1 && n) { printf("Case %d: ", kase++); to_get(n); } return 0;}
阅读全文
0 0
- uva 10791
- uva 10791
- Uva 10791
- UVA 10791
- UVA 10791
- uva 10791
- UVA 10791
- uva 10791
- UVA 10791
- uva 10791 溢出
- Uva 10791MininumSumLCM
- uva
- UVA
- UVA
- UVA
- uva
- UVA
- UVA
- [Hackerrank]hourrank 19-What Are the Odds?
- 图像超分辨率技术
- 指针建树
- 1、思考数据结构中逻辑结构、物理结构、操作运算三个方面的内容
- Crontab 设置定时抽取任务
- uva 10791
- [poj1204][caioj1465][AC自动机]地图匹配
- 简单实现日夜间模式切换
- [LeetCode-Algorithms-13] "Roman to Integer" (2017.9.22-WEEK3)
- GPRS模块与STM32的数据传输
- 51nod 1419 最小公倍数挑战
- Selenium遇到的问题6 利用fiddler抓包工具,Host总是显示Tunnel to
- 2. Add Two Numbers。
- 训练集---训练赛11