Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- #include <algorithm>
- #include <iostream>
- #include <cstring>
- #include <cstdlib>
- #include <cassert>
- #include <sstream>
- #include <numeric>
- #include <string>
- #include <vector>
- #include <cstdio>
- #include <bitset>
- #include <cmath>
- #include <ctime>
- #include <queue>
- #include <stack>
- #include <map>
- #include <set>
- using namespace std;
- #define sz(a) (int)a.size()
- #define vi vector <int>
- #define pb push_back
- #define mp make_pair
- #define ll long long
- #define f first
- #define s second
- const int inf = (int)1e9;
- const int mod = inf + 7;
- const double eps = 1e-9;
- const double pi = acos(-1.0);
- ll n;
- string s;
- string f(ll n){
- string res = "";
- while(n != 0){
- res += char('0' + n % 2);
- n /= 2;
- }
- reverse(res.begin(), res.end());
- return res;
- }
- string next(string s){
- string d = "";
- for(int i = 1; i < s.size(); ++i)
- d += s[i];
- d += s[0];
- return d;
- }
- ll bpow(ll a, ll n){
- if(n == 0)
- return 1;
- if(n == 1)
- return a;
- else {
- ll k = bpow(a, n / 2);
- if(n % 2 == 0)
- return k * k;
- else
- return k * k * a;
- }
- }
- ll u(string s){
- ll res = 0;
- for(ll i = s.size() - 1; i >= 0; --i)
- res += bpow(2, s.size() - i - 1) * (s[i] - '0');
- return res;
- }
- int main(){
- cin >> n;
- if(n == 0){
- cout << 0 << endl;
- return 0;
- }
- string p = f(n);
- string maxi = "";
- for(int i = 0; i < p.size() + 2; ++i){
- if(maxi < p)
- maxi = p;
- p = next(p);
- }
- cout << u(maxi) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement