fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. typedef long long ll;
  5.  
  6.  
  7. vector<ll> lucky_nums;
  8. void generate_lucky(ll number){
  9.  
  10. lucky_nums.push_back(number);
  11.  
  12. if(number > 1e10) return;
  13.  
  14. generate_lucky((number * 10) + 4);
  15. generate_lucky((number * 10) + 7);
  16. };
  17.  
  18.  
  19. int main() {
  20. FAST
  21. ll n;
  22. cin >>n;
  23. int fours,sevens;
  24. generate_lucky(0);
  25. vector<ll> result;
  26. lucky_nums.erase(lucky_nums.begin());
  27. for(auto c : lucky_nums){
  28. string check = to_string(c);
  29. fours = 0;
  30. sevens = 0;
  31. for(int i = 0;i<check.length();i++){
  32. if(check[i]=='4'){
  33. fours++;
  34. }
  35. else {
  36. sevens++;
  37. }
  38. }
  39. if (fours==sevens && (sevens!=0||fours!=0)){
  40. result.push_back(c);
  41. }
  42.  
  43. }
  44. sort(result.begin(),result.end());
  45.  
  46. cout << *lower_bound(result.begin(),result.end(),n) << "\n";
  47.  
  48. // system("pause");
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
4447474774