Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ======================
- [ ___T_ ]
- [ | - + | ]
- [ |__v__|=> HI:-) ]
- [ .=[::+]=. ]
- [ ]=' [___] '=[ ]
- [ / | ]
- [ _\ |_ ]
- ======================
- */
- #include<bits/stdc++.h>
- using namespace std;
- using lli = int64_t;
- const int maxN = 1200;
- lli isVisited[maxN / 64 + 200];
- vector<int> primes;
- void bitwise_seive_gen(int limit){
- limit += 100;
- for(lli i = 3; i <= sqrt(limit) ; i += 2){
- if(!(isVisited[i/64]&(1LL<<(i%64)))) {
- for(long long j = i * i; j <= limit; j += 2 * i) {
- isVisited[j/64] |= (1LL<<(j%64));
- }
- }
- }
- primes.push_back(2);
- for(lli i = 3; i <= limit; i += 2){
- if(!(isVisited[i / 64] & (1LL << (i % 64)))) {
- primes.push_back(i);
- }
- }
- }
- lli grid[maxN - 940][maxN][15];
- int n,k;
- lli solve(int i,int j,int count){
- if(i == (int) primes.size() or j >= n or count >= k){
- return (j == n and count == k);
- }
- if(grid[i][j][count] != -1){
- return grid[i][j][count];
- }
- return grid[i][j][count] = solve(i + 1,j + primes[i],count + 1) + solve(i + 1,j,count);
- }
- int main(){
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- bitwise_seive_gen(maxN);
- while(cin >> n >> k and n != 0 and k != 0){
- memset(grid,-1,sizeof(grid));
- cout << solve(0,0,0) << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement