forked from anshuman8800/Interivew-Questions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGCDPermutation.cpp
More file actions
50 lines (50 loc) · 873 Bytes
/
GCDPermutation.cpp
File metadata and controls
50 lines (50 loc) · 873 Bytes
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
// link for the question: https://www.codechef.com/problems/PERMGCD
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
const ll N = 100000;
const ll M = (ll)1000000007;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll t;
cin >> t;
while (t--)
{
ll n, x;
cin >> n >> x;
ll temp = (n * (n + 1)) / 2;
if (x < n || x > temp)
{
cout << "-1\n";
}
else if (x == n)
{
for (ll i = 0; i < n; i++)
{
cout << i + 1 << " ";
}
cout << "\n";
}
else
{
cout << x - n + 1 << " ";
for (int i = 1; i < n; i++)
{
if (i >= x - n + 1)
{
cout << i + 1 << " ";
}
else
{
cout << i << " ";
}
}
cout << "\n";
}
}
return 0;
}