UVA 10791 - Minimum Sum LCM(坑)

时间:2021-09-15 19:29:34

题目链接

不知道为什么,我用cin,cout就是过不了。。。改成scanf过了。。。

还是我居然理解错题意了,已经不能用看错了。。。至少两个数字,我理解成两个数字了,还写了个爆搜。。。

 #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
#define LL long long
#define MOD 1000000007
int prim[];
int o[];
LL que[];
int main()
{
int cas = ,i,j,num = ,m;
LL n,temp;
for(i = ;i <= ;i ++)
{
if(!o[i])
{
prim[num++] = i;
for(j = i+i;j <= ;j += i)
o[j] = ;
}
}
while(scanf("%lld",&n)!=EOF)
{
if(!n) break;
printf("Case %d: ",cas++);
if(n == )
{
printf("2\n");
continue;
}
m = ;
for(i = ;i < num;i ++)
{
if(n == ) break;
if(n%prim[i] == )
{
temp = ;
while(n%prim[i] == )
{
temp *= prim[i];
n /= prim[i];
}
que[m++] = temp;
}
}
if(n != )
que[m++] = n;
LL minz = ;
if(m == )
{
printf("%lld\n",que[]+);
continue;
}
for(i = ;i < m;i ++)
{
minz += que[i];
}
printf("%lld\n",minz);
}
return ;
}