UVA - 10791 Minimum Sum LCM(最小公倍数的最小和)
题意:输入整数n(1<=n<231),求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小。输出最小的和。
分析:
1、将n分解为a1p1*a2p2……,每个aipi作为一个单独的整数时最优。
2、n为1时,len==0;n为素数时,len==1。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
vector<LL> v;
void deal(LL n){//将n分解成因子
v.clear();
LL m = (LL)sqrt(n + 0.5);
for(LL i = 2; i <= m; ++i){
if(n % i == 0){//n中的质因子
LL tmp = 1;
while(n % i == 0 && n > 1){
tmp *= i;
n /= i;
}
v.push_back(tmp);//由质因子i合并成的因子
}
if(n <= 1) break;
}
if(n > 1) v.push_back(n);//素数本身
}
int main(){
LL N;
int kase = 0;
while(scanf("%lld", &N) == 1){
if(!N) return 0;
deal(N);
LL ans = 0;
int len = v.size();
if(len == 0 || len == 1){//1或素数
ans = N + 1;
}
else{
for(int i = 0; i < len; ++i){
ans += v[i];
}
}
printf("Case %d: %lld\n", ++kase, ans);
}
return 0;
}
UVA - 10791 Minimum Sum LCM(最小公倍数的最小和)的更多相关文章
- UVA.10791 Minimum Sum LCM (唯一分解定理)
UVA.10791 Minimum Sum LCM (唯一分解定理) 题意分析 也是利用唯一分解定理,但是要注意,分解的时候要循环(sqrt(num+1))次,并要对最后的num结果进行判断. 代码总 ...
- UVA 10791 Minimum Sum LCM(分解质因数)
最大公倍数的最小和 题意: 给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 那么找出一个序列,使他们的和最小. 分析: 一系列数字a1,a2,a3 ...
- UVa 10791 Minimum Sum LCM【唯一分解定理】
题意:给出n,求至少两个正整数,使得它们的最小公倍数为n,且这些整数的和最小 看的紫书--- 用唯一分解定理,n=(a1)^p1*(a2)^p2---*(ak)^pk,当每一个(ak)^pk作为一个单 ...
- UVa 10791 - Minimum Sum LCM(唯一分解定理)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 数论-质因数(gcd) UVa 10791 - Minimum Sum LCM
https://vjudge.net/problem/UVA-10791/origin 以上为题目来源Google翻译得到的题意: 一组整数的LCM(最小公倍数)定义为最小数,即 该集合的所有整数的倍 ...
- UVA 10791 - Minimum Sum LCM(坑)
题目链接 不知道为什么,我用cin,cout就是过不了...改成scanf过了... 还是我居然理解错题意了,已经不能用看错了...至少两个数字,我理解成两个数字了,还写了个爆搜... #includ ...
- UVA 10791 Minimum Sum LCM
唯一分解定理 把n分解为 n=a1^p1*a2^p2*...的形式,易得每个ai^pi作为一个单独的整数最优. 坑: n==1 ans=2: n因子种数只有一个 ans++: 注意溢出 ...
- Minimum Sum LCM(uva10791+和最小的LCM+推理)
L - Minimum Sum LCM Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submi ...
- Minimum Sum LCM(uva 10791)
题意(就是因为读错题意而wa了一次):给一个数字n,范围在[1,2^23-1],这个n是一系列数字的最小公倍数,这一系列数字的个数至少为2 例如12,是1和12的最小公倍数,是3和4的最小公倍数,是1 ...
随机推荐
- spyder崩溃修复
实验室突然断电,重启电脑后spyder崩溃 在anaconda命令行中输入命令失败 StackOverflow上找的解决方案,适合win10系统,简单粗暴 在win10搜索里面找,点一下就自动修复了
- android 动态壁纸开发
转:http://www.eoeandroid.com/thread-100389-1-1.html android 动态壁纸开发参考:http://www.ophonesdn.com/article ...
- JavaScript函数用法
本文我们来学习下js函数的一些用法. 上图的要点为: 1.函数具有属性,如foo.length和foo.name. 2.arguments是类数组,arguments.length为实参的数目. 3. ...
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
打个小广告:本人开发了一个宠物相关的App,欢迎大家下载体验~ 下载二维码: 进入正文: 之前发过一篇博客,也是对这两个的练习使用,但是之后遇到些问题,所以删除重写了.抱歉 Masonry是一款轻量级 ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 按钮:按钮标签
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Problem A: Assembly Required K路归并
Problem A: Assembly Required Princess Lucy broke her old reading lamp, and needs a new one. The cast ...
- Tensorflow官方文档 input_data.py 下载
说明: 本篇文章适用于MNIST教程下载数据集. # Copyright 2015 Google Inc. All Rights Reserved. # # Licensed under the Ap ...
- <BitMap>大名鼎鼎的bitmap算法
BitMap 抛砖引玉 首先,我们思考一个问题:如何在3亿个整数(0~2亿)中判断某一个数是否存在?现在只有一台机器,内存只有500M 这个问题像不像我们之前提到过的一个在0-10个数中,判断某一个数 ...
- Readiness 探测【转】
除了 Liveness 探测,Kubernetes Health Check 机制还包括 Readiness 探测. 用户通过 Liveness 探测可以告诉 Kubernetes 什么时候通过重启容 ...
- BGR to RGB排列
BGR to RGB排列 2012年09月27日 13:59:48 雷电羊 阅读数:4759 https://blog.csdn.net/cjsycyl/article/details/80247 ...