链接
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1732
题解
分解质因数
N
=
∏
i
=
1
k
p
i
q
i
N=\prod_{i=1}^kp_i^{q_i}
N=∏i=1kpiqi
那么答案就是
∑
i
=
1
k
p
i
q
i
\sum_{i=1}^kp_i^{q_i}
∑i=1kpiqi
特判
k
=
1
k=1
k=1和
k
=
0
k=0
k=0的情况
代码
//水题
#include <bits/stdc++.h>
#define maxn 100010
#define ll long long
#define linf (1ll<<60)
using namespace std;
ll ans, lis[maxn], prime[maxn], mark[maxn], N;
ll read(ll x=0)
{
ll f=1, c;
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-48;
return f*x;
}
void preprocess()
{
ll i, j;
for(i=2;i<maxn;i++)
{
if(!mark[i])prime[++*prime]=i;
for(j=1;j<=*prime and i*prime[j]<maxn;j++)
{
mark[i*prime[j]]=1;
if(i%prime[j]==0)break;
}
}
}
void split(ll n)
{
ll i, t=n;
for(i=1;prime[i]*prime[i]<=t and i<=*prime and t>1;i++)
if(t%prime[i]==0)
{
lis[++*lis]=1;
while(t%prime[i]==0)t/=prime[i], lis[*lis]*=prime[i];
}
if(t>1)lis[++*lis]=t;
}
void work()
{
ll i, ans=0;
if(N==1)
{
printf("2\n");
return;
}
if(*lis==1)
{
printf("%lld\n",N+1);
return;
}
for(i=1;i<=*lis;i++)ans+=lis[i];
printf("%lld\n",ans);
}
int main()
{
ll kase=0;
preprocess();
while(N=read())
{
*lis=0;
split(N);
printf("Case %lld: ", ++kase);
work();
}
return 0;
}