#t397. 质数和分解(prime)

质数和分解(prime)

Prime Sum Decomposition

Problem Background

Special for beginners, ^_^

Problem Description

Any natural number N>1N>1 can be written as a sum of primes each between 22 and NN (including the case of a single number), and there may be more than one such prime-sum expression. For example, 99 has four essentially different prime-sum expressions: $$9 = 2+5+2 = 2+3+2+2 = 3+3+3 = 2+7$$

Two expressions are considered essentially the same if one can be obtained from the other simply by reordering the terms.

Write a program to compute how many essentially different prime-sum expressions a natural number NN can be written as.

Input Format

Multiple test cases. Each line contains one natural number NN, 2≤N≤2002\le N\le 200.

Output Format

For each natural number NN, output the number of essentially different prime-sum expressions, one per line.

Sample Input 1

2

Sample Output 1

1

Sample Input 2

200

Sample Output 2

9845164

Constraints

2≤N≤2002\le N\le 200.

Time limit 1s, memory limit 1024KiB for each test case.

Hint

Approach 1:

Step 1 – Divide into stages by the primes used.

Step 2 – Define state: f[i][j] = number of ways to make sum jj using the first ii primes.

Step 3 – Transition: $f[i][j]=\sum_{k=0}^{\lfloor j/p[i]\rfloor}f[i-1][j-k\ast p[i]]$, where p[i]p[i] is the ii-th prime.

Step 4 – Initial value: f[0][0]=1.

Approach 2:

Transition: f[i][j] = f[i-1][j] + f[i][j-p[i]]; // for j≥p[i]j\ge p[i]