-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecret Origins.cpp
126 lines (115 loc) · 5.45 KB
/
Secret Origins.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
https://lightoj.com/problem/secret-origins
/** Author: Md. Sakib Uddin.
From: RMSTU **/
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ld long double
#define sl(x) scanf("%lld", &x)
#define sll(x, y) scanf("%lld %lld", &x, &y)
#define slll(x, y, z) scanf("%lld %lld %lld", &x, &y, &z)
#define printl(x) printf("%lld\n")
#define printll(x,y) printf("%lld %lld\n")
#define printlll(x,y,z) printf("%lld %lld %lld\n")
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(d,min3(a,b,c))
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(d,max3(a,b,c))
#define lcm(a,b) (a*b)/gcd(a,b)
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define all(x) x.begin(),x.end()
#define reall(x) x.rbegin(),x.rend()
#define eb emplace_back
#define pb push_back
#define popb pop_back
#define pf push_front
#define popf pop_front
#define mk make_pair
#define F first
#define S second
#define fori(i,b,e) for(int (i)=(b); (i) <= (e); (i)++)
#define for0(i,n) for(int (i)=0; (i) < (n); (i)++)
#define forrv(i,b,e) for(int i=b;i>=e;i--)
#define sp(a) fixed<<setprecision(a)
#define endl '\n'
#define yes cout << "YES" << '\n'
#define no cout << "NO" << '\n'
#define coutl(x) cout << x << '\n'
#define cout(x) cout << x
#define nl cout << '\n'
#define CASE(t) printf("Case %lld: ",++t)
#define pi 2*acos(0)
#define inf 0x3f3f3f3f
#define E 2.71828182845904523536
#define gamma 0.5772156649
/**_____________________________________DEBUG____________________________________________________**/
template<typename T>void showSTL(T H);template<typename T,typename V>void showSTL(pair<T,V> H);
template<typename T>void showSTL(priority_queue<T> H);template<typename T>void showSTL(stack<T> H);
template<typename T,typename V>void showSTL(map<T,V> H);
template<typename T,typename V>void showSTL(multimap<T,V> H);template<typename T>void showSTL(vector<T> H);
template<typename T>void showSTL(set<T> H);template<typename T>void showSTL(multiset<T> H);
template<typename T>void showSTL(list<T> H);void showSTL(char *H);
template<typename T>void showSTL(deque<T> H);template<typename T>void showSTL(queue<T> H);
template<typename T>void showSTL(T H){stringstream ss;ss<<H;cerr<<ss.str();}
template<typename T,typename V>void showSTL(pair<T,V> H){cerr<<"(";showSTL(H.first);cerr<<"=>";showSTL(H.second);cerr<<")";}
template<typename T>void showSTL(priority_queue<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}cerr<<endl;}
template<typename T>void showSTL(stack<T> H){cerr<<endl;while(!H.empty()){cerr<<H.top()<<endl;H.pop();}}
template<typename T,typename V>void showSTL(map<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T,typename V>void showSTL(multimap<T,V> H){cerr<<"[ ";for(auto val:H){showSTL(val);cerr<<" ";}cerr<<"]";}
template<typename T>void showSTL(vector<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(set<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(multiset<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(list<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
void showSTL(char *H){for(int i=0;i<strlen(H);i++){showSTL(H[i]);};}
template<typename T>void showSTL(deque<T> H){cerr<<"[ ";for(auto val : H){showSTL(val);cerr<<' ';}cerr<<"]";}
template<typename T>void showSTL(queue<T> H){cerr<<"[ ";while(!H.empty()){showSTL(H.front());cerr<<' ';H.pop();}cerr<<"]";}
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,__attribute__((unused))int LINE_NUM)
{cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << "):";
cerr<<" "<<args[idx]<<" = ";showSTL(H);dbg_out(args,idx+1,LINE_NUM, T...);}
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
string Onoroy(ll n){
string s = "";
while(n > 0){
if(n%2 == 1) s += '1';
else s += '0';
n = n / 2;
}
return s;
}
ll Dec(string s)
{
ll x = 1, res = 0;
for0(i,s.size())
{
if(s[i] == '1') res += x;
x *= 2;
}
return res;
}
int main()
{
ll t = 0, tt;
cin >> tt;
while(tt--)
{
ll n; cin >> n;
string p = Onoroy(n);
p += '0';
reverse(all(p));
next_permutation(all(p));
reverse(all(p));
ll ans = Dec(p);
CASE(t);
coutl(ans);
}
}