-
Notifications
You must be signed in to change notification settings - Fork 0
/
10276.cpp
54 lines (39 loc) · 925 Bytes
/
10276.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll arr[52];
void generate(){
vector<ll> bil; unordered_map<ll, ll> index;
bil.push_back(1);
arr[1] = 1;
index[1] = 0;
ll k = 2;
while(bil.size() <= 50){
ll kud = bil.size() * bil.size();
ll sel = abs(kud - k);
if(sel==k || index[sel] == -1 || k >= kud){
arr[bil.size()] = k-1;
bil.push_back(k);
index[k] = bil.size() - 1;
k++;
continue;
}
bil[index[sel]] = k;
index[k] = index[sel];
index[sel] = -1;
k++;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
generate();
ll t; cin >> t;
while(t--){
ll n; cin >> n;
cout << arr[n] << "\n";
}
return 0;
}