UVA 10791 -唯一分解定理的应用
#include<iostream> #include<stdio.h> #include<algorithm> #include<string.h> #include<math.h> #define ll long long using namespace std; int main(){ int n; int k=0; while(1){ k++; scanf("%d",&n); if (n==0)break; int m=sqrt(n+1); int cnt=0; ll ans=0; for (int i=2;i<=m;i++){ if (n%i==0){ ll num=1; cnt++; while(n%i==0){ num*=i; n/=i; } ans+=num; } if (n==1)break; } if (n!=1 || cnt==0){ ans+=n; cnt++; } if (cnt==1){ ans++; } printf("Case %d: %lld\n",k,ans); } return 0; }
有不懂欢迎咨询
QQ:1326487164(添加时记得备注)