Математика отвечает утвердительно на оба вопроса:
Код:
G = Graph[(#[[1]] \[UndirectedEdge] #[[2]]) & /@Select[Subsets[Range[24], {2}],PrimeQ[#[[1]] + #[[2]]] &]]; Apply[List,FindHamiltonianCycle[G, 2], {2}]
Код:
{{{1, 18}, {18, 11}, {11, 12}, {12, 17}, {17, 2}, {2, 21}, {21,
8}, {8, 23}, {23, 6}, {6, 13}, {13, 10}, {10, 19}, {19, 4}, {4,
15}, {15, 16}, {16, 3}, {3, 20}, {20, 9}, {9, 14}, {14, 5}, {5,
24}, {24, 7}, {7, 22}, {22, 1}}, {{1, 18}, {18, 11}, {11, 6}, {6,
23}, {23, 8}, {8, 21}, {21, 2}, {2, 17}, {17, 12}, {12, 19}, {19,
10}, {10, 13}, {13, 4}, {4, 15}, {15, 16}, {16, 3}, {3, 20}, {20,
9}, {9, 14}, {14, 5}, {5, 24}, {24, 7}, {7, 22}, {22, 1}}}