fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #define ll long long
  5. #define endl '\n'
  6. ll N = 1e9+7;
  7. ll oo =1e13;
  8. const ll maxx = 1000000 + 3;
  9. ll n,m,k,q,x,y,z,l,r,mid,ans;
  10.  
  11. void go(ll num){
  12. //4 ,7 ,44,47,74,77
  13. }
  14. void solve() {
  15. cin>>n;
  16.  
  17. ll j=0;
  18. vector<ll>v={4,7};
  19. for (ll i =0;i<10;i++) {
  20. for (;j<v.size();j++) {
  21. if (v[j]>1e9)break;
  22. v.push_back(v[j]*10+4);
  23. v.push_back(v[j]*10+7);
  24. }
  25. }
  26. vector<ll>v2;
  27. for (ll i =0;i <v.size();i++) {
  28. ll num=v[i];
  29. ll f=0,s=0;
  30. while (num>0) {
  31. if (num%10==4)f++;
  32. else s++;
  33. num/=10;
  34. }
  35. if (f==s) v2.push_back(v[i]);
  36. }
  37. cout<<*lower_bound(v2.begin(),v2.end(),n);
  38. }
  39. int main() {
  40. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  41. ll t=1 ;
  42. // cin >>t;
  43. while (t--) {
  44. ans=0;
  45. solve();
  46. }
  47. }
Success #stdin #stdout 0.01s 5316KB
stdin
4500
stdout
4747