Advertisement
Vserosbuybuy

C6. E

Apr 13th, 2021
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement