漏洞百出!! #include <iostream> #include <cmath> #include <string> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } //#define TEST int main() { #ifdef TEST freopen("input.txt", "r", stdin); #endif int n; int t = 1; while(cin >> n && n != 0) { cout << "Case " << t++ << ": "; if(n == 1) { cout << 2 << endl; continue; } if(n == 2147483647) { cout << 2147483648 << endl; continue; } int m = sqrt((float)n); int ans = 0; int tmpn = n; int count = 0; for(int i = 2; i <= m; i++) { if(tmpn % i == 0) { count++; int tmp = 1; while(tmpn % i == 0) { tmp *= i; tmpn /= i; } ans += tmp; } } if(tmpn == n) cout << 1 + n << endl; else { if(tmpn != 1) ans += tmpn; //素因子只有一个的情况!!omg。 else if(count == 1) ans++; cout << ans << endl; } } return 0; }