El_GEMMY

lucky numbers

Jul 30th, 2022
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.  
  7.     ios_base::sync_with_stdio(false);
  8.     cin.tie();
  9.  
  10.     freopen("input.txt", "r", stdin);
  11.     freopen("output.txt", "w", stdout);
  12.  
  13.     int a, b; cin >> a >> b;
  14.     bool found = false;
  15.     for(int i = a; i <= b; i++){
  16.         bool is_lucky = true;
  17.  
  18.         int x = i;
  19.         while(x){
  20.             int curr_digit = x % 10;
  21.             if(curr_digit != 7 and curr_digit != 4)
  22.                 is_lucky = false;
  23.             x /= 10;
  24.         }
  25.         if(is_lucky){
  26.             found = true;
  27.             cout << i << ' ';
  28.         }
  29.     }
  30.     if(not found)
  31.         cout << -1;
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment