fork download
  1. uses math;
  2.  
  3. const fi='';
  4. fo='';
  5. maxn=10;
  6.  
  7. type data=longint;
  8.  
  9. var x :array[1..2*maxn] of longint;
  10. i,j,n,m :longint;
  11. st :array[1..2*maxn] of longint;
  12. kq :array[1..10001,1..2*maxn] of longint;
  13. res :int64;
  14. cx :array[1..2*maxn] of boolean;
  15.  
  16. procedure enter;
  17. begin
  18. assign(input,fi);reset(input);
  19. readln(n);
  20. close(input);
  21. end;
  22.  
  23. function ngto(x : longint) : boolean;
  24. var i :longint;
  25. begin
  26. for i:=2 to trunc(sqrt(x)) do
  27. if x mod i = 0 then exit(false);
  28. exit(true);
  29. end;
  30.  
  31. procedure cnkl;
  32. begin
  33. if ngto(x[2*n]+x[1]) then
  34. begin
  35. inc(res);
  36. if res<=10000 then
  37. kq[res] := x;
  38. end;
  39. end;
  40.  
  41. procedure try(i : longint);
  42. var j :longint;
  43. begin
  44. for j:= 1 to 2*n do
  45. if cx[j] then
  46. if ngto(j+x[i-1]) then
  47. begin
  48. x[i] := j;
  49. cx[j] := false;
  50. if i=2*n then cnkl else try(i+1);
  51. cx[j] := true;
  52. end;
  53. end;
  54. procedure process;
  55. begin
  56. {for i:=2 to 2*n do
  57.   if ngto(i) then
  58.   begin
  59.   inc(m);
  60.   st[m] := i;
  61.   end; }
  62. fillchar(cx,sizeof(cx),true);
  63. cx[1] := false;
  64. x[1] := 1;
  65. try(2);
  66. end;
  67.  
  68. procedure print;
  69. begin
  70. assign(output,fo);rewrite(output);
  71. writeln(res);
  72. for i:=1 to min(res,10000) do
  73. begin
  74. for j:=1 to 2*n do write(kq[i,j],' ');
  75. writeln;
  76. end;
  77. close(output);
  78. end;
  79.  
  80. begin
  81. enter;
  82. process;
  83. print;
  84. end.
Success #stdin #stdout 0s 4412KB
stdin
Standard input is empty
stdout
0