Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define SZ(v) (int((v).size()))
- #define pb push_back
- vector<ll> lucky;
- void pre_calc (ll num) {
- if (num > 1e10)
- return;
- lucky.pb(num);
- pre_calc((num * 10) + 7);
- pre_calc((num * 10) + 4);
- }
- void run () {
- int n;
- cin >> n;
- pre_calc(0);
- sort(lucky.begin(), lucky.end());
- for (int i = 0; i < SZ(lucky); ++i) {
- if (lucky[i] >= n) {
- int four, seven;
- four = seven = 0;
- ll cur = lucky[i];
- while (cur) {
- if (cur % 10 == 4)
- four++;
- else
- seven++;
- cur /= 10;
- }
- if (four == seven) {
- cout << lucky[i] << '\n';
- return;
- }
- }
- }
- }
- int main () {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- // freopen("/home/hamoudi/clion/hello.in", "rt", stdin);
- int tt;
- tt = 1;
- // cin >> tt;
- while (tt--)
- run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement