• UVA 10791 -唯一分解定理的应用


    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<string.h>
    #include<math.h>
    #define ll long long
    using namespace std;
    int main(){
      int n;
      int k=0;
      while(1){
         k++;
         scanf("%d",&n);
        if (n==0)break;
        int m=sqrt(n+1);
        int cnt=0;
        ll ans=0;
        for (int i=2;i<=m;i++){
            if (n%i==0){
                ll num=1;
                cnt++;
                while(n%i==0){
                    num*=i;
                    n/=i;
                }
               ans+=num;
            }
            if (n==1)break;
        }
        if (n!=1 || cnt==0){
            ans+=n;
            cnt++;
        }
        if (cnt==1){
            ans++;
        }
        printf("Case %d: %lld
    ",k,ans);
    
      }
      return 0;
    }
    有不懂欢迎咨询 QQ:1326487164(添加时记得备注)
  • 相关阅读:
    Robberies
    Big Event in HDU
    UVA 562 Dividing coins
    Little Rooks
    Bone Collector
    Piggy-Bank
    0-1背包问题之——饭卡
    Monkey and Banana
    The Triangle
    Burning Midnight Oil
  • 原文地址:https://www.cnblogs.com/bluefly-hrbust/p/9819925.html
Copyright © 2020-2023  润新知