-
Notifications
You must be signed in to change notification settings - Fork 2
/
LOJ-1097 Lucky Number.cpp
50 lines (40 loc) · 1.3 KB
/
LOJ-1097 Lucky Number.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
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define Bismillah__Kun_Fayakun ios_base :: sync_with_stdio(false);
#define ll long long
#define MAXN 200007
#define orderedSet tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
int main ()
{
Bismillah__Kun_Fayakun
int idx = 1;
orderedSet os;
for (int i = 1; i<=1429431; i += 2) os.insert(i);
while(idx <os.size())
{
int itemToRemove = *os.find_by_order(idx);
if (itemToRemove <= os.size())
{
itemToRemove--;
os.erase(os.find_by_order(itemToRemove));
int tobeAdded = itemToRemove; itemToRemove += itemToRemove;
while(itemToRemove < os.size())
{
os.erase(os.find_by_order(itemToRemove));
itemToRemove += tobeAdded;
}
}
else break;
idx++;
}
int test_case, case_no = 0; scanf("%d", &test_case);
while(test_case--)
{
int idx; scanf("%d", &idx); --idx;
printf("Case %d: %d\n", ++case_no, *os.find_by_order(idx));
}
return 0;
}