Minimum Sum LCM - UVa 10791
来源:互联网 发布:数据产品经理招聘 编辑:程序博客网 时间:2024/05/18 00:27
Minimum Sum LCM
Minimum Sum LCM
LCM (Least Common Multiple) of a set of integers is defined as the minimum number, which is a multiple of all integers of that set. It is interesting to note that any positive integer can be expressed as the LCM of a set of positive integers. For example 12 can be expressed as the LCM of 1, 12 or12, 12 or 3, 4 or 4, 6 or 1, 2, 3, 4 etc.
In this problem, you will be given a positive integer N. You have to find out a set of at least two positive integers whose LCM is N. As infinite such sequences are possible, you have to pick the sequence whose summation of elements is minimum. We will be quite happy if you just print the summation of the elements of this set. So, for N = 12, you should print 4+3 = 7 asLCM of 4 and 3 is 12 and 7 is the minimum possible summation.
Input
The input file contains at most 100 test cases. Each test case consists of a positive integer N ( 1N231 - 1).
Input is terminated by a case where N = 0. This case should not be processed. There can be at most 100 test cases.
Output
Output of each test case should consist of a line starting with `Case #: ' where # is the test case number. It should be followed by the summation as specified in the problem statement. Look at the output for sample input for details.
Sample Input
121050
Sample Output
Case 1: 7Case 2: 7Case 3: 6
题意:将一个数分解成至少两个数的最小公倍数,求着几个数的和的最小值。
思路:分解素数后,将素数的幂,就是这些数中的一个。
AC代码如下:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;int vis[100010],prime[100010],num;int main(){ int n,n2,t=0,i,j,k,p; ll ans; for(i=2;i<=100000;i++) if(vis[i]==0) { prime[++num]=i; for(j=i*2;j<=100000;j+=i) vis[j]=1; } while(~scanf("%d",&n) && n>0) { k=0;ans=0;n2=n; for(i=1;i<=9592;i++) if(n%prime[i]==0) { k++;p=1; while(n%prime[i]==0) { n/=prime[i]; p*=prime[i]; } ans+=p; } if(n!=1) { ans+=n; k++; } ans+=max(0,2-k); printf("Case %d: %lld\n",++t,ans); }}
- uva 10791 - Minimum Sum LCM
- uva 10791 - Minimum Sum LCM
- UVa 10791 - Minimum Sum LCM
- UVA 10791 - Minimum Sum LCM
- UVA 10791 Minimum Sum LCM
- UVa:10791 Minimum Sum LCM
- uva 10791 - Minimum Sum LCM
- UVA - 10791 Minimum Sum LCM
- UVA 10791 - Minimum Sum LCM
- UVA 10791 - Minimum Sum LCM
- UVA 10791 Minimum Sum LCM
- UVa 10791 - Minimum Sum LCM
- Minimum Sum LCM - UVa 10791
- UVa 10791 - Minimum Sum LCM
- UVA - 10791 Minimum Sum LCM
- UVA 10791 - Minimum Sum LCM
- UVa 10791 Minimum Sum LCM
- uva 10791 Minimum Sum LCM
- C 算法精介----链表->双向链表
- C# 中使用Word文档对图像进行操作
- tomcat使用指南(一)-安装部署
- UVA 270 Lining Up(多点共线)
- POJ 3660 Cow Contest 传递闭包
- Minimum Sum LCM - UVa 10791
- 转义符插曲
- 在ubuntu下获取对应内核源码命令
- RMI、Hessian、Burlap、Httpinvoker、WebService的比较
- git push 出现 you are not allowed to upload merges 错误提示
- 蒲公英:一站式免费应用内测平台
- 几种通讯协议的比较RMI > Httpinvoker >= Hessian >> Burlap >> web service
- 2014年度总结
- 写给大家看的量子力学——量子通信、量子隐形传输技术简介