Advertisement
Derga

Untitled

Sep 29th, 2023 (edited)
868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool IsGood(uint64_t num) {
  6.     char last_digit = '0' + (num % 2);
  7.     num /= 2;
  8.     int cnt = 1;
  9.     while (num > 0)
  10.     {
  11.         char digit = '0' + (num % 2);
  12.         num /= 2;
  13.  
  14.         if (last_digit != digit) {
  15.             cnt++;
  16.             last_digit = digit;
  17.         }
  18.         if (cnt > 3) {
  19.             return false;
  20.         }
  21.     }
  22.  
  23.     return cnt == 3;
  24. }
  25.  
  26. int main() {
  27.     ios_base::sync_with_stdio(false);
  28.     cin.tie(nullptr);
  29.  
  30.     uint64_t from;
  31.     uint64_t to;
  32.     cin >> from >> to;
  33.  
  34.     uint64_t grow_days_cnt = 0;
  35.  
  36.     while (from <= to) {
  37.         if (IsGood(from)) {
  38.             ++grow_days_cnt;
  39.         }
  40.         ++from;
  41.     }
  42.  
  43.     cout << grow_days_cnt;
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement