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
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值