Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bitset>
- using namespace std;
- typedef unsigned long long uint;
- int main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- uint n;
- cin >> n;
- if (n == 0) {
- cout << 0;
- return 0;
- }
- uint x = n;
- uint maxx = n;
- int cnt = -1;
- while (x != 0) {
- x = x >> 1; // x >>= 1;
- cnt++;
- }
- x = (n >> 1) | ((n & 1) << cnt);
- while (x != n) {
- maxx = max(maxx, x);
- x = (x >> 1) | ((x & 1) << cnt);
- }
- cout << maxx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement