uva 10791

https://vjudge.net/problem/UVA-10791

最小公倍数的最小和

将n分解质因数:p1^k1 + p2^k2 + ……

每一项独立时和最小

特殊情况:n=1 ans=2

                 n=质数 ans++

#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    int n,T=0;
    long long ans;
    while(1)
    {
        scanf("%d",&n);
        if(n==1) { printf("Case %d: 2
",++T); continue; }
        if(!n) return 0;
        ans=0; 
        int m=sqrt(n),cnt=0;
        for(int i=2;i<=m;i++)
        {
            if(n%i==0)
            {
                int t=1;
                while(n%i==0)
                 {
                      n/=i; t*=i;
                 }
                ans+=t;
                cnt++; 
            }
        }
        if(n>1) ans+=n,cnt++;
        if(cnt==1) ans++;
        printf("Case %d: %lld
",++T,ans);
    }
}
原文地址:https://www.cnblogs.com/TheRoadToTheGold/p/7348959.html