题意:
输入一个整数n, 求至少两个正整数,使他们的LCM是n, 且让整数和尽可能的小。
解题思路:
将n使用唯一分解定理分解,每位上每个素因子根据指数, 算出它的幂, 加起来就是最小的和。
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1732
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<list>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
#define FOR(i, s, t) for(int i = (s) ; i <= (t) ; ++i)
#define REP(i, n) for(int i = 0 ; i < (n) ; ++i)
int buf[10];
inline long long read()
{
long long x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')
{
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void writenum(int i)
{
int p = 0;
if(i == 0) p++;
else while(i)
{
buf[p++] = i % 10;
i /= 10;
}
for(int j = p - 1 ; j >= 0 ; --j) putchar('0' + buf[j]);
}
/**************************************************************/
#define MAX_N
const int INF = 0x3f3f3f3f;
long long f(long long n)
{
long long m = n;
long long sum = 0;
for(int i = 2; i <= sqrt(n+ 0.0) ; i++)
{
long long tmp = 1;
while(n % i ==0)
{
tmp *= i;
n /= i;
}
if(tmp != 1)
{
sum += tmp;
}
}
if(sum == 0)
{
sum += n + 1;
}
else if(n != 1)
{
sum += n;
}
else if(sum == m)
{
sum++;
}
return sum;
}
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out2.txt", "w", stdout);
int cas = 1;
long long n;
while(scanf("%lld", &n) && n)
{
long long ans = f(n);
printf("Case %d: %lld\n", cas++, ans);
}
return 0;
}