The boundary judgment and recursive writing methods are not the same as before, so we need to summarize them more.
Include <stdio. h>
# Include <string. h>
Int prime [45];
Int used [22];
Int Quan [22];
Int N;
Void DFS (INT );
Int main ()
{
Int T = 0;
Memset (Prime, 0, sizeof (PRIME ));
Prime [2] = prime [3] = prime [5] = prime [7] = prime [11] = prime [13] = prime [17] = prime [19] = prime [23] = prime [29] = prime [31] = prime [37] = 1;
While (scanf ("% d", & N )! = EOF)
{
Memset (used, 0, sizeof (used ));
Quan [0] = 1;
Printf ("case % d: \ n", ++ t );
If (n = 1)
{
Printf ("1 \ n ");
Continue;
}
DFS (1 );
Putchar ('\ n ');
}
Return 0;
}
Void DFS (INT atemp)
{
Int I, J;
If (atemp = N)
{
If (prime [Quan [atemp-1] + 1])
{
Printf ("1 ");
For (j = 1; j <atemp; j ++)
Printf ("% d", Quan [J]);
Putchar ('\ n ');
}
Return;
}
For (I = 2; I <= N; I ++)
{
If (! Used [I] & prime [Quan [atemp-1] + I])
{
Used [I] = 1;
Quan [atemp] = I;
DFS (atemp + 1 );
Used [I] = 0;
}
}
}