permutations.cpp (370B)
1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 void solve() 6 { 7 long n; 8 cin >> n; 9 if (n == 1) { 10 cout << "1\n"; 11 return; 12 } 13 if (n < 4) { 14 cout << "NO SOLUTION\n"; 15 return; 16 } 17 18 for (int i = (n+1)/2; i < n; i++) { 19 cout << (2-n%2)+(i*2)%n << " "; 20 } 21 for (int i = 0; i < (n+1)/2; i++) { 22 cout << 1+(i*2)%n << " "; 23 } 24 25 cout << "\n"; 26 } 27 28 int main() 29 { 30 solve(); 31 }