2006-01-19 Accepted 1.434 4344 |
~cpp // 884 - Factorial Factors #include <iostream> using namespace std; #define MAXN 1000000 static int fact[MAXN+1]; void findFact() { int i, j; for (i = 2; i <= MAXN; i++) { if (fact[i] == 0) // 소수 { fact[i] = 1; for (j = i + i; j <= MAXN; j+=i) fact[j] = i; } else // 합성수 fact[i] = fact[i/fact[i]] + fact[fact[i]]; } for (i = 2; i < MAXN; i++) fact[i+1] += fact[i]; } int main() { int n; findFact(); while (cin >> n) cout << fact[n] << endl; return 0; }