zoukankan      html  css  js  c++  java
  • UVA 10791

    #include<bits/stdc++.h>
    #include<iostream>
    #include<stdio.h>
    #include<cmath>
    #define maxn 10000000
    using namespace std;
    int a[maxn];
    int b[maxn];
    int n;
    long long pow(int a,int b)
    {
        long long res=1;
        while(b--)
            res*=a;
        return res;
    }
    void factor(int n,int &tot){
        int temp,i,now;
        temp=(int)((double)sqrt(n)+1);
        tot=0;
        now=n;
        for(i=2;i<=temp;++i)if(now%i==0){
            a[++tot]=i;
            b[tot]=0;
            while(now%i==0){
                ++b[tot];
                now/=i;
            }
        }
        if(now!=1){
            a[++tot]=now;
            b[tot]=1;
        }
    }
    int id=1;
    long long ans;
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif // ONLINE_JUDGE
        long long num;
        while(cin>>num)
        {
            if(num==0)break;
            if(num==1)
            {
                cout<<"Case "<<id++<<": "<<2<<endl;continue;
            }
            ans=0;
            factor(num,n);
            if(n==1){cout<<"Case "<<id++<<": "<<1ll*pow(a[1],b[1])+1<<endl;continue;}
    
            for(int i=1;i<=n;i++)
            {
                ans+=pow(a[i],b[i]);
                //cout<<c[i]<<endl;
                //cout<<total<<endl;
            }
            //cout<<"total:"<<total<<endl;
            cout<<"Case "<<id++<<": "<<ans<<endl;
        }
    }
    
  • 相关阅读:
    第0次作业
    第4次作业
    第3次作业
    第2次作业
    C#浮点数保留位数
    第0次作业
    软件工程第4次作业
    软件工程第3次作业
    软件工程第2次作业
    软件工程第1次作业
  • 原文地址:https://www.cnblogs.com/linruier/p/9532583.html
Copyright © 2011-2022 走看看