## Sum of Different Primes (ICPC Asia 2006 D)

### 実装

#include <iostream>
#include <array>
#include <vector>
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat(i,n) repeat_from(i,0,n)
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(i))
#define repeat_reverse(i,n) repeat_from_reverse(i,0,n)
typedef long long ll;
using namespace std;
vector<int> primes(int n) {
vector<bool> is_prime(n+1, true);
is_prime[0] = false;
is_prime[1] = false;
for (int i = 2; i * i <= n; ++ i) {
if (is_prime[i]) {
for (int j = 2*i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
vector<int> result;
for (int i = 0; i <= n; ++ i) {
if (is_prime[i]) {
result.push_back(i);
}
}
return result;
}
constexpr int max_n = 1120;
constexpr int max_k = 14;
int main() {
vector<int> ps = primes(max_n);
array<array<ll,max_k+1>,max_n+1> dp = {};
dp[0][0] = 1;
for (int p : ps) {
repeat_reverse (k, max_k+1) {
repeat (n, max_n+1) {
if (n-p >= 0 and k-1 >= 0) {
dp[n][k] += dp[n-p][k-1];
}
}
}
}
while (true) {
int n, k; cin >> n >> k;
if (n == 0 and k == 0) break;
cout << dp[n][k] << endl;
}
return 0;
}