Advertisement
Malinovsky239

CodeForces Beta Round # 77 (div2, task B)

Jul 9th, 2011
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long LL;
  8.  
  9. LL res = LL(1e16), n;
  10.  
  11. void rec(LL now, int f, int s)
  12. {
  13.     if (now > res)
  14.         return;
  15.     if (now >= n)
  16.     {
  17.         if (f == s)
  18.         {
  19.             res = min(now, res);
  20.             return;
  21.         }
  22.     }
  23.     rec(now * 10 + 4, f + 1, s);
  24.     rec(now * 10 + 7, f    , s + 1);
  25. }
  26.  
  27. int main()
  28. {  
  29.     cin >> n;
  30.     rec(0, 0, 0);
  31.     cout << res;
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement