Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define int long long
- #pragma GCC optimization("O3")
- using namespace std;
- int32_t main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr); cout.tie(nullptr);
- unsigned int n;
- cin >> n;
- unsigned int now = 1;
- while(now<<1U <= n)
- now <<= 1U;
- string s = "0";
- while(now >= 1U){
- if(n >= now)
- n -= now, s += '1';
- else
- s += '0';
- if(now == 1)
- break;
- now >>= 1U;
- }
- unsigned int ans = 0;
- now = 0;
- bool fnd = false;
- for(char i : s){
- if(now == 0){
- fnd = 1 - (i - '0');
- now++;
- continue;
- }
- if(fnd == i - '0')
- fnd = 1 - fnd, now++;
- else {
- ans = max(ans, now);
- now = 1;
- fnd = 1 - (i - '0');
- }
- }
- ans = max(ans, now);
- cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment