at the beginning, the card got stuck badly. Then it was optimized. Instead, it was Tlm. After reading other people's problem-solving reports, I found that the check function I wrote was complicated and used three cycles, in fact, we can do this in two cycles. We also learned to evaluate the prime number by using the limit method.
# Include <iostream> # include <memory. h> # include <math. h> # include <stdio. h> using namespace STD; int result [1001]; bool used [1001]; bool isprime [10010]; int D, M, N, num; int DFS (INT ); bool isfound; bool check (INT); void prime_list (); int main () {prime_list (); While (CIN> N> m> D &&! (N = 0 & M = 0 & D = 0) {isfound = false; num = m-n + 1; memset (used, false, 1001 * sizeof (bool); DFS (0); If (isfound) {for (INT I = 0; I <num-1; I ++) printf ("% d, ", result [I]); printf (" % d \ n ", result [num-1]);} elseprintf (" no anti-prime sequence exists. \ n ") ;}return 0 ;}int DFS (INT current) {If (isfound) return 0; If (! Check (current) return 0; If (current = num) {isfound = true; return 0 ;}for (INT I = 0; I <num &&! Isfound; I ++) {If (! Used [I]) {used [I] = true; Result [current] = N + I; DFS (current + 1); used [I] = false ;}} return 0;} bool check (INT current) {int sum = 0; If (current <= 1) return true; For (INT I = 0; I <current; I ++) {sum = 0; if (I + D <Current) for (Int J = 0; j <D; j ++) {sum + = Result [I + J]; If (j> 1 & isprime [Sum]) return false;} else {for (Int J = I; j <current; j ++) {sum + = Result [J]; If (J-I> 0 & isprime [Sum]) return Fal Se ;}}return true;} // evaluate 1 ~ using the Evaluate Method ~ Void prime_list () {int I, j; memset (isprime, true, sizeof (isprime); isprime [0] = false; isprime [1] = false; // Note: The minimum positive factor of n not equal to 1 is not greater than the square root of N (I = 2; I * I <= 10000; I ++) {J = 2; If (isprime [I]) {While (I * j <= 10000) {isprime [I * j] = false; j ++ ;}}}}