UVA 10791 Minimum Sum LCM(质因数分解+数学分析)
来源:互联网 发布:网络营销策划什么意思 编辑:程序博客网 时间:2024/06/05 18:19
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
题意:给定一个数n,求至少两个数的lcm=n,然后使得它们的和最小。
分析:我们通过lcm的意义可以知道对n进行质因数分解以后,那些数所构成的集合的质因数分解后任意因子的质数已定要等于n质因数分解后相同因子的指数,根据这一条,我们就确定了这些集合中任一因子的指数的最大值,并且根据和最小的思路,那么这个质因数在其他数中已定是0,所以我们就很自然的按照一条思路找到了我们的策略:对n进行质因数分解之后a^q作为单独一个数
//// main.cpp// Uva 10791//// Created by 张嘉韬 on 16/8/2.// Copyright © 2016年 张嘉韬. All rights reserved.//#include <iostream>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef unsigned long long ll;ll counter,r;ll init(ll n){ if(n==1) return 2; counter=0; r=0; ll temp=(int)((double)sqrt(n)+1); for(ll i=2;i<=temp;i++) { if(n%i==0) { ll ans=1; counter++; while(n%i==0) { ans=i*ans; n=n/i; } r+=ans; } } if(n!=1) {r+=n;counter++;} if(counter==1) return r+1; else return r;}int main(int argc, const char * argv[]) { //freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin); ll n; int t=0; while(scanf("%lld",&n)==1) { //cout<<"shit"<<endl; if(n==0) break; t++; cout<<"Case "<<t<<": "<<init(n)<<endl; } return 0;}
- UVA 10791 Minimum Sum LCM(质因数分解+数学分析)
- UVA 10791 Minimum Sum LCM(质因数分解)
- UVa 10791 Minimum Sum LCM(分解质因数)
- UVA - 10791 Minimum Sum LCM 数学题 ,质因数分解
- Minimum Sum LCM 唯一分解定理+求质因数UVA
- 【Uva10791】Minimum Sum LCM【LCM】【质因数分解】
- UVa 10791 - Minimum Sum LCM 质因数分解加素数筛优化
- UVA10791 Minimum Sum LCM 质因数分解
- UVa11889 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 (唯一分解定理)
- jQuery源码研究分析学习笔记-jQuery原型属性和方法(九)
- 你的产品没有一炮而红,后面该怎么办?
- 安卓实用方法,类,接口
- java 采用MD5加密解密
- luci流程简介
- UVA 10791 Minimum Sum LCM(质因数分解+数学分析)
- RMQ算法之Sparse Table算法
- HDU 5442 Favorite Donut(最大表示法)
- Kali Linux 支持 pecl
- TCP/IP、Http、Socket的区别
- java 抽象类
- 计算某年的1月1号是星期几
- POJ 1125 可不可能遍历所有点情况下的最短路径
- ANDROID SDK体系介绍