Vserosbuybuy

C6. E

Apr 13th, 2021
447
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <bitset>
  3.  
  4. using namespace std;
  5.  
  6. typedef unsigned long long uint;
  7.  
  8. int main() {
  9. #ifdef _DEBUG
  10.     freopen("input.txt", "r", stdin);
  11.     freopen("output.txt", "w", stdout);
  12. #endif
  13.     uint n;
  14.     cin >> n;
  15.     if (n == 0) {
  16.         cout << 0;
  17.         return 0;
  18.     }
  19.     uint x = n;
  20.     uint maxx = n;
  21.     int cnt = -1;
  22.     while (x != 0) {
  23.         x = x >> 1; // x >>= 1;
  24.         cnt++;
  25.     }
  26.     x = (n >> 1) | ((n & 1) << cnt);
  27.     while (x != n) {
  28.         maxx = max(maxx, x);
  29.         x = (x >> 1) | ((x & 1) << cnt);
  30.     }
  31.  
  32.     cout << maxx;
  33.     return 0;
  34. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×