1 #include <iostream> 2 #include <string.h> 3 #include <string> 4 #include <fstream> 5 #include <algorithm> 6 #include <stdio.h> 7 #include <vector> 8 #include <queue> 9 #include <set> 10 #include <cmath> 11 using namespace std; 12 const double eps = 1e-8; 13 const int INF=0x7fffffff; 14 unsigned long long uINF = ~0LL; 15 #define MAXN 10000007 16 typedef long long LL; 17 LL vis[MAXN]; 18 LL prime[MAXN]; 19 20 void sieve(LL n) 21 { 22 LL m=(LL)sqrt(n+0.5); 23 memset(vis,0,sizeof(vis)); 24 for(LL i=2;i<=m;i++)if(!vis[i]) 25 for(LL j=i*i;j<=n;j+=i)vis[j]=1; 26 } 27 28 LL gen_prime(LL n) 29 { 30 sieve(n); 31 LL c=0; 32 for(LL i=2;i<=n;i++)if(!vis[i]) 33 prime[c++]=i; 34 return c; 35 } 36 37 LL gcd(LL a,LL b) 38 { 39 return b==0?a:gcd(b,a%b); 40 } 41 42 LL solve(LL n) 43 { 44 LL flag=0,np=0; 45 LL temp=n,sum=0,num; 46 for(LL i=2;i*i<=temp;i+=2) 47 { 48 //cout<<i<<' '; 49 num=1; 50 while(temp%i==0) 51 { 52 if(num==1)flag++; 53 temp/=i;num*=i; 54 } 55 if(num==1)num=0; 56 sum+=num; 57 if(i==2)i--; 58 np++; 59 } 60 if(temp>1){flag++;sum+=temp;} 61 if(flag==0||flag==1)sum=n+1; 62 return sum; 63 } 64 65 int main() 66 { 67 LL t=1; 68 LL n; 69 while(scanf("%lld",&n),n) 70 { 71 printf("Case %lld: %lld ",t++,solve(n)); 72 } 73 74 return 0; 75 }
分解质因子 相同的累乘 不同的累加