1114. 素数环

NBC++

include < cstdio>

include < iostream>

include < cmath>

using namespace std;
void circle (int i,int T);
bool isprime (int a,int b);

int a[21] ;
bool b[21] ;
int d [11] = {2,3,5,7,11,13,17,19,23,29,31};
int cnt;
int main (){
int T;
cin >> T;
a [21] = {0};
a [1] = 1 ;
b [21] = {0};
cnt = 1;
circle (2,T);
}

void circle (int i,int T){

int j;
for (j =2;j&lt;=T;j++){
    if (isprime(j,a[i-1]) &amp;&amp; !b[j] || i ==1){
        a[i] = j;
        b[j] = 1;
        if (i ==T &amp;&amp; isprime(1,a[T])) {
            /*cout &lt;&lt; cnt ++ &lt;&lt;" :";*/
            int k ;
            for (k =1;k&lt;=T;k++)
            cout &lt;&lt; a[k] &lt;&lt; " ";
            cout &lt;&lt; endl;
        }
        else circle (i+1,T);
        b [j] = 0;
    } 
}

}

bool isprime (int a,int b){
int c = a+b;
int i ;
bool flag = 0;
for (i =0;c >= d [i] && i < 11;i++)
if ( c == d[i]) flag =1;
return flag ;
}

你当前正在回复 博客/题目
存在问题!