UVA10791 Minimum Sum LCM 质因数分解
来源:互联网 发布:微信收费数据共享 编辑:程序博客网 时间:2024/04/28 14:09
Description
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 or 12, 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 as LCM 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
Problem setter: Md. Kamruzzaman
Special Thanks: Shahriar Manzoor
Miguel Revilla 2004-12-10
Source
Root :: AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 6. Mathematical Concepts and Methods
Root :: AOAPC I: Beginning Algorithm Contests -- Training Guide (Rujia Liu) :: Chapter 2. Mathematics :: Basic Problems
Root :: Competitive Programming 3: The New Lower Bound of Programming Contests (Steven & Felix Halim) :: Mathematics :: Number Theory :: Working with Prime Factors
Root :: Prominent Problemsetters :: Md. Kamruzzaman (KZaman)
Root :: Competitive Programming 2: This increases the lower bound of Programming Contests. Again (Steven & Felix Halim) :: Mathematics :: Number Theory :: Working with Prime Factors
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;typedef long long int LL;LL n;LL ans(LL n){ LL ret=0,num=0; if(n==1) return 2LL; LL m=sqrt(n+0.5); for(LL i=2;i<=m&&n!=1;i++) { if(n%i) continue; LL temp=1LL; num++; while(n%i==0) { n/=i;temp*=i; } ret+=temp; } if(n!=1) { num++; ret+=n; } if(num<2) ret+=1; return ret;}int main(){ int cas=1; while(scanf("%lld",&n)!=EOF&&n) { printf("Case %d: %lld\n",cas++,ans(n)); } return 0;}
- 【Uva10791】Minimum Sum LCM【LCM】【质因数分解】
- UVA10791 Minimum Sum LCM 质因数分解
- uva10791——Minimum Sum LCM(分解质因数)
- uva10791 Minimum Sum LCM(唯一分解定理)
- UVA10791 Minimum Sum LCM(唯一分解定理)
- uva10791 - Minimum Sum LCM
- UVA10791- Minimum Sum LCM
- UVA10791----Minimum Sum LCM
- uva10791 Minimum Sum LCM
- uva10791 Minimum Sum LCM
- uva10791 Minimum Sum LCM
- UVA10791 Minimum Sum LCM
- UVa11889 Minimum Sum LCM 分解质因数
- UVA 10791 Minimum Sum LCM(质因数分解)
- UVA10791 - Minimum Sum LCM(分解质因子)
- Uva10791 Minimum Sum LCM(数论、唯一分解定理)
- 唯一分解定理(Minimum Sum LCM,Uva10791)
- UVa 10791 Minimum Sum LCM(分解质因数)
- .net HttpWebRequest Post xml
- [PAT]1005. Spell It Right (20)
- 看似无所作为的三天
- Spring核心(ioc控制反转)
- Spring定时任务配置
- UVA10791 Minimum Sum LCM 质因数分解
- 第十一周项目四阶乘
- Hadoop大数据零基础高端实战培训
- Best Time to Buy and Sell Stock II
- 第十一周项目6——4
- Linux下的 .o、.a、.so文件
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 6 Blackjack
- 总结openstack和cloudfoundry大型软件的架构共性
- mysql存储过程及常用函数