1 条题解

  • 0
    @ 2025-9-10 8:58:58

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    #define MAXNUM (777777777)
    #define MAXN (100000 + 5)
    
    int T;
    int a, b;
    
    long long _p[MAXN];
    int _p_c;
    
    long long ans;
    
    void dfs(long long s) {
        if (s > MAXNUM) return ;
    
        _p[_p_c++] = s;
    
        dfs (1LL * s * 10 + 4);
        dfs (1LL * s * 10 + 7);
    }
    
    
    void init () {
        memset(_p, 0, sizeof(_p));
        _p_c = 0;
        dfs(0);
        _p[_p_c] = 4444444444LL;
        sort(_p, _p + _p_c);
    //    for (int i=0; i<_p_c; i++) {
    //        printf ("%d ", _p[i]);
    //    }
    //    printf("\n_p_c: %d\n", _p_c);
    }
    
    int main () {
    
    //    freopen("B.in", "r", stdin);
        init();
    //    cout << lower_bound(_p, _p + _p_c, 74) - _p <<endl;
    
        scanf ("%d", &T);
        while (T--) {
            scanf("%d %d", &a, &b);
    
            int l = lower_bound(_p, _p + _p_c, a) - _p;
            int r = lower_bound(_p, _p + _p_c, b) - _p;
    
    //        cout << l << " " << r << endl;
    
            ans = 0;
    
            if (a <= _p[l]) {
                ans += (long long)1 * _p[l] * (_p[l] - a + 1);
            }
    
    //        cout << ans << endl;
            for (int i=l; i<r; i++) {
                ans += (long long)1 * _p[i+1] * (_p[i+1] - _p[i]);
            }
    
    //        cout << ans << endl;
    //
            if (_p[r] > b) {
                ans -= (long long)1 * _p[r] * (_p[r] - b);
    //            cout << _p[r] << " " << (b - _p[r-1]) << endl;
            }
            cout << ans << endl;
        }
    }
    
    
    • 1

    信息

    ID
    3503
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者