hdu 4345

View Code
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<vector>
 5 #define MAXN 1003
 6 using namespace std;
 7 typedef long long int ll;
 8 vector<int> prime;
 9 ll dp[MAXN][MAXN];
10 
11 void pp()
12 {
13      bool vis[1000] = {false};
14      for (int i(2); i<1000; ++i) {
15          if (!vis[i]) {
16             vis[i] = true;
17             prime.push_back(i);
18             for (int j(i*i); j<1000; j+=i) {
19                  vis[j] = true;    
20             }
21          }    
22      }
23 }
24 
25 int main()
26 {
27     int n;
28     pp();
29     while (scanf("%d",&n) != EOF) {
30         memset(dp,0,sizeof(dp));
31         int end(0);
32         for (int i(0); i<prime.size(); ++i) {
33             if (prime[i] > n)break;
34             end++;
35         }
36         for (int i(0); i<end; ++i) {
37             for (int j(1); j<=n; ++j)dp[j][i] += dp[j][i-1];
38             for (int j(prime[i]); j<=n; j *= prime[i]) {
39                 for (int k(1); k<=n; ++k) {
40                     if (i == 0)break;
41                     if (k + j <= n) {
42                        dp[k+j][i] += dp[k][i-1];      
43                     } 
44                 }    
45                 dp[j][i]++;
46             }    
47         }      
48         
49         ll ans(1);
50         for (int i(1); i<=n; ++i) {
51             ans += dp[i][end-1];    
52         }
53         cout<<ans<<endl;
54     }
55     return 0;    
56 }
posted on 2012-08-10 10:29  Dev-T  阅读(186)  评论(0编辑  收藏  举报