extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::fmt::{Display, Error, Formatter, Binary};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet};

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}
macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}
fn primes(upper_limit: usize) -> Vec<usize> {
    let mut is_prime = vec![true; upper_limit + 1];
    let mut i = 4;
    while i <= upper_limit {
        is_prime[i] = false;
        i += 2;
    }
    i = 3;
    while i * i <= upper_limit {
        if is_prime[i] {
            let mut j = i * i;
            while j <= upper_limit {
                is_prime[j] = false;
                j += i;
            }
        }
        i += 2;
    }
    let mut result = Vec::new();
    for i in 2 .. is_prime.len() {
        if is_prime[i] {
            result.push(i);
        }
    }
    result
}
fn f(n: usize, k: usize, max: usize, primes: &Vec<usize>, memo: &mut Vec<Vec<Vec<i64>>>) -> i64 {
    if k == 0 {
        if n == 0 { 1 } else { 0 }
    }else if n <= 0 || max == 0 {
        0
    }else if memo[n - 1][max - 1][k - 1] >= 0 {
        memo[n - 1][max - 1][k - 1]
    }else {
        let mut res = 0_i64;
        for i in k - 1 .. max {
            if n >= primes[i] {
                res += f(n - primes[i], k - 1, i, primes, memo);
            }
        }
        memo[n - 1][max - 1][k - 1] = res;
        res
    }
}
fn main() {
    let prime = primes(1120);
    let mut memo = vec![vec![vec![-1_i64;14];prime.len()];1120];
    loop {
        let_all!(n: usize, k: usize);
        if n == 0 && k == 0{
            return 
        }
        println!("{}", f(n, k, prime.len(), &prime, &mut memo));
    }
}


Measured memory_bytes: 33708