-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutations.cpp
More file actions
105 lines (99 loc) · 2.11 KB
/
Permutations.cpp
File metadata and controls
105 lines (99 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
``````````````
``` STAY ```
``` WITH ```
``` PALESTINE ```
``` ```
``` ```
````````````
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define cout(n) cout << n << endl;
#define tc ll t; cin >> t; while(t--)
//Check Prime Numberr:
bool Prime(int n){
// Corner case
if (n <= 1)
return false;
for (int i = 2; i <= sqrt(n); i++)
if (n % i == 0)
return false;
return true;
}
bool fact(int n){
int factorial = 1;
for(int i = 1; i <= n; i++){
factorial *= i;
}
return factorial;
}
bool Composite(int n){
if(!Prime(n)){
return true;
}
else{
return false;
}
}
//Binary Serching
bool bin_search(int l, int r, int A[], int x){
while(l <= r){
int mid = (l + r) / 2;
if(A[mid] == x){
return true;
}
else{
if(A[mid] < x){
l = mid + 1;
}
else{
r = mid - 1;
}
}
}
return false;
}
ll Digit_sum(ll n){
ll sum = 0;
while(n > 0){
sum += n % 10;
n /= 10;
}
return sum;
}
void solve(){
int n; cin >> n;
if(n <= 3 and n != 1) cout << "NO SOLUTION" << endl;
else{
if(n == 4){
cout << "3 1 4 2" << endl;
}
else{
vector<int> even, odd;
for(int i = 1; i <= n; i++){
if(i % 2 == 0){
even.push_back(i);
}
else{
cout << i << ' ';
}
}
for(int i = 0; i < even.size(); i++){
cout << even[i] << ' ';
}
}
cout << endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
solve();
return 0;
}