UVA10791
题目
做法
分解一下:\(n=p_1^{k_1}p_2^{k_2}...p_n^{k_n}\),易证\(a+b<a\cdot b(a,b≥2)\),把\(n\)分解成\(p_1^{k_1},p_2^{k_2}...,p_n^{k_n}\),有几个特判,细节看代码吧
My complete code
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL kase;
inline void Solve(LL n){
LL ans(0),N(n),cnt(0);
if(n==1){
printf("Case %d: 2\n",++kase);
return;
}
for(LL i=2;i*i<=N;++i){
LL num(1);
if(n%i==0 && n!=1){
while(n%i==0 && n!=1){
num*=i,
n/=i;
}
++cnt;
ans+=num;
}
}
if(n==N || cnt==1)
++ans;
if(n!=1) ans+=n;
printf("Case %d: %lld\n",++kase,ans);
}
int main(){
LL n;
while(scanf("%lld",&n)!=EOF&&n)
Solve(n);
return 0;
}