Divide N into the form of prime number addition. The prime number must be smaller than K and the prime number cannot appear continuously. The order of prime numbers is different in addition.
Given N, K, are there several ways to add prime numbers? Questions & examples
I used to create a huge table. Look at what I wrote below. It's amazing !!! Memory-based search, DP thinking...
# Include <iostream> # include <cstdio> # include <cmath> # include <string> # include <cstring> # include <cstdlib> # include <algorithm> using namespace STD; # define M 1004int num [m]; int P [m]; int N, K; void PRI () {memset (Num, 0, sizeof (Num )); int CNT = 1; num [1] = 1; for (INT I = 2; I <= 36; I ++) {If (Num [I] = 0) {P [CNT ++] = I; for (Int J = I * 2; j <60; j + = I) num [J] = 1 ;}}} void solve () {CIN> N> K; int DP [55] [55]; int ans [55]; ans [1] = 0; memset (DP, 0, sizeof (DP); For (int tmp = 2; TMP <= N; TMP ++) {ans [TMP] = 0; If (! Num [TMP] & TMP <= k) {DP [TMP] [TMP] = 1; ans [TMP] ++;} For (INT I = 2; I <TMP; I ++) {if (I> K) break; If (Num [I]) continue; DP [TMP] [I] + = (ANS [TMP-I]-DP [TMP-I] [I]); ans [TMP] + = DP [TMP] [I] ;}} cout <ans [N] <Endl ;}int main () {int T; scanf ("% d", & T); PRI (); For (int cas = 1; CAS <= T; CAS ++) {solve ();} return 0 ;}