forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base2palindrome.cpp
69 lines (58 loc) · 1.06 KB
/
base2palindrome.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string tostr(ll n) {
string s;
while(n > 0) {
s.push_back(n%2+'0');
n >>= 1;
}
return s;
}
ll toint(string s) {
ll ans = 0;
for(auto i : s) {
ans <<= 1;
if(i == '1') {
ans++;
}
}
return ans;
}
ll gen1(ll i) {
string s, t;
s = t = tostr(i);
reverse(t.begin(), t.end());
string end = t + s;
return toint(end);
}
ll gen2(ll i) {
string s, t;
s = t = tostr(i);
reverse(t.begin(), t.end());
string end = t + '1' + s;
return toint(end);
}
ll gen3(ll i) {
string s, t;
s = t = tostr(i);
reverse(t.begin(), t.end());
string end = t + '0' + s;
return toint(end);
}
int main() {
ll n;
cin >> n;
set<ll> s;
s.insert(0);
s.insert(1);
for(ll i = 0; i < 50000; i++) {
s.insert(gen1(i));
s.insert(gen2(i));
s.insert(gen3(i));
}
for(ll i = 0; i < n; i++) {
s.erase(*s.begin());
}
cout << *s.begin() << endl;
}