ProgMe

Untitled

Dec 13th, 2020
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int32_t main()
  6. {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr); cout.tie(nullptr);
  9. unsigned long long n;
  10. cin >> n;
  11. auto s = bitset<128>(n);
  12. unsigned long long ans = 0;
  13. unsigned long long now = 1;
  14. bool fnd = s[s.size() - 1] == true;
  15. for(int i = s.size() - 2; i >= 0; i--){
  16. if(fnd == s[i]){
  17. fnd = !fnd;
  18. now++;
  19. }
  20. else {
  21. ans = max(ans, now);
  22. now = 1;
  23. fnd = s[i] != true;
  24. }
  25. }
  26. ans = max(ans, now);
  27. cout << ans;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment