5 solutions

  • 0
    @ 2025-4-13 11:02:33
    #include <bits/stdc++.h>
    using namespace std;
    
    string to_base9(int x) {
        string s;
        if (x == 0) return "0";
        while (x > 0) {
            s += (x % 9) + '0';
            x /= 9;
        }
        reverse(s.begin(), s.end());
        return s;
    }
    
    int main() {
        int N, M;
        cin >> N >> M;
        int count = 0;
        for (int x = N; x <= M; ++x) {
            string s = to_base9(x);
            bool all_odd = true;
            for (char c : s) {
                if (c != '1' && c != '3' && c != '5' && c != '7') {
                    all_odd = false;
                    break;
                }
            }
            if (!all_odd) continue;
            if (s == string(s.rbegin(), s.rend())) {
                count++;
            }
        }
        cout << count << endl;
        return 0;
    }
    

    Information

    ID
    680
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    # Submissions
    58
    Accepted
    20
    Uploaded By