标签:div col ons += nbsp log case 最小公倍数 system
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 using namespace std; 6 const int maxn = 110; 7 long long f[maxn], ccount; 8 9 void init(long long n){ 10 long long m = (long long)sqrt(n + 0.5); 11 ccount = 0; 12 for (long long i = 2; i <= m && n > 1; i++){ 13 if (n%i == 0){ 14 long long fac = 1; 15 while (n%i == 0 && n > 1){ 16 fac *= i; 17 n /= i; 18 } 19 f[ccount++] = fac; //fac是处理后的因子 20 } 21 } 22 if (n > 1) 23 f[ccount++] = n; 24 /* 25 for (int i = 0; i < ccount; i++){ 26 printf("**%lld\n", f[i]); 27 } 28 */ 29 } 30 31 int main(){ 32 long long n; 33 int cnt = 0; 34 while (scanf("%lld", &n) && n){ 35 cnt++; 36 init(n); //将n分解成因子 37 long long ans = 0; 38 if (!ccount || ccount == 1){ 39 ans = n + 1; 40 } 41 else{ 42 for (int i = 0; i < ccount; i++){ 43 ans += f[i]; 44 } 45 } 46 printf("Case %d: %lld\n", cnt, ans); 47 } 48 //system("pause"); 49 return 0; 50 }
标签:div col ons += nbsp log case 最小公倍数 system
原文地址:http://www.cnblogs.com/jaydenouyang/p/7647756.html