<span style="font-size:14px;">特殊情况多,看注释</span>
#include<cstdio>
#include<cstring>
#include<iostream>
#define maxn 100000
#include<cmath>
#define LL long long
using namespace std;
int cas;
LL n;
LL mul(LL a,LL b){
if(b==0)return 0;
LL ans=1;
for(;b;b>>=1){
if(b&1)ans=ans*a;
a=a*a;
}
return ans;
}
int main(){
while(scanf("%d",&n)&&n){
cas++;
if(n==1){//显然
printf("Case %d: 2\n",cas);
continue;
}
LL ans=0,tot=0;
bool ok=false;
for(int i=2;i<=sqrt(n+0.5);i++){
int cnt=0;
while(n%i==0){
cnt++;
n/=i;
ok=true;//如果本身是素数
}
if(cnt)tot++;
ans+=mul((LL)i,(LL)cnt);
if(n==1)break;
}
if(!ok)ans=n+1;//本身是素数
else if(n!=1)ans+=n;//唯一分解最后还是剩一个素数
else if(tot==1)ans++;//只有一个质因数(他们的最小公倍数就是自身,所以就是他本身和一)
printf("Case %d: %lld\n",cas,ans);
}
return 0;
}
【UVA 10791】最小公倍数的最小和
最新推荐文章于 2019-02-22 12:57:38 发布