您的位置:首页 > 其它

uva 10791 和最小的LCM

2017-07-26 15:48 323 查看
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
long long n;
int t=1;
while(~scanf("%lld",&n)&&n)
{
long long x=n,res=0,len=(long long)sqrt(n);
int cnt=0;
for(long long i=2;i<=len&&x>1;i++)
{
if(x%i==0)
{
cnt++;
long long int t=1;
while(x%i==0&&x>1)
{
t*=i;
x/=i;
}
res+=t;
}
}
if(x>1)
{
res+=x;
cnt++;
}
if(cnt<2)
printf("Case %d: %lld\n",t++,n+1);
else
printf("Case %d: %lld\n",t++,res);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: