UVA 10791

来源:互联网 发布:mac格式化ntfs格式 编辑:程序博客网 时间:2024/06/05 03:04

题目的链接      https://vjudge.net/contest/190690#problem/A

题意“”给一个数字n,范围在[1,2^23-1],n是一系列数字的最小公倍数,,这一系列数字的个数至少为2  个,求这一系列数字的和的

最小,  废话不多,直接ac 代码

#include<stdio.h>
#include <string.h>
#include <math.h>
typedef long long LL;
LL n;
LL a[1005];
LL k;
LL f (LL n)
{ LL y=(LL)sqrt(n);
LL k=0;
LL fact =1;

for( LL i=2;i<y;i++)
{
if(n%i==0)
{ fact=1;

while(n%i==0)
{ fact=fact*i;
n=n/i;


}

a[k++]=fact;
}


}

if(n>1)
a[k++]=n;
return k;


}
int main()
{ int casea=1;
while(scanf("%lld",&n)&&n)
{
if(n==1)
{
printf("Case %d: %lld\n",casea++,2);
continue;
}
memset(a,0,sizeof(a));
long long len=f(n);
if(a[0]==n)
{
printf("Case %d: %lld\n",casea++,n+1);
continue;
}
LL ans=0;


for(LL i=0;i<len;i++)
{
ans+=a[i];
}
printf("Case %d: %lld\n",casea++,ans);
}


return 0;
}