Submission details
Task:Toistot
Sender:ollpu
Submission time:2025-12-20 16:39:40 +0200
Language:C++ (C++20)
Status:READY
Result:11
Feedback
groupverdictscore
#1ACCEPTED11
#20
#30
#40
Test results
testverdicttimegroup
#1ACCEPTED0.01 s1, 2, 3, 4details
#20.01 s2, 3, 4details
#30.01 s3, 4details
#40.01 s4details
#5ACCEPTED0.01 s1, 2, 3, 4details
#60.01 s4details

Code

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define D(x) {x;}
#else
#define D(x)
#endif
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int N = 19;
int pr[N], pr2[N];

ll f(ll x) {
    if (x >= 1000'000'000'000'000'000) x--;
    if (x <= 10) return 0;
    ll base = 1;
    ll a9 = 0;
    ll res = 0;
    for (int l = 1; l < N; ++l) {
        ll pbase = base;
        base *= 10;
        a9 *= 10;
        a9 += 9;
        ll pat = 1;
        for (int r = 2; l * r < N; ++r) {
            ll mult;
            if (pr[r]) mult = 1;
            else if (pr2[r]) mult = -1;
            else mult = 0;
            pat *= base;
            pat += 1;
            ll hi = x / pat;
            hi = min(hi, a9);
            ll lo = pbase;
            if (mult) {
                D(cout << l*r << " " << l << " " << r << " " << mult << endl);
                D(cout << pat << " " << pbase << " " << a9 << endl);
            }
            if (lo <= hi) res += mult*(hi-lo+1);
        }
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    for (int x = 2; x < N; ++x) pr[x] = 1;
    for (int x = 2; x < N; ++x) {
        for (int y = 2*x; y < N; ++y) pr[y] = 0;
    }
    for (int x = 2; x < N; ++x) {
        for (int y = 2; x*y < N; ++y) {
            if (pr[x] && pr[y] && x != y) pr2[x*y] = 1;
        }
    }
    int t;
    cin >> t;
    for (int ti = 0; ti < t; ++ti) {
        ll a, b;
        cin >> a >> b;
        cout << f(b) - f(a-1) << '\n';
    }
}

Test details

Test 1

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
1000
633 906
727 914
585 884
750 792
...

correct output
3
2
2
1
0
...

user output
3
2
2
1
0
...

Test 2

Group: 2, 3, 4

Verdict:

input
1000
647761 927345
744364 840268
598715 905836
767448 810881
...

correct output
303
105
333
48
95
...

user output
303
105
333
48
95
...

Feedback: Incorrect character on line 30 col 2: expected "442", got "439"

Test 3

Group: 3, 4

Verdict:

input
1000
663307073 949601845
762227828 860434499
613084013 927576203
785866095 830342436
...

correct output
286
98
314
44
89
...

user output
286
98
314
44
89
...

Feedback: Incorrect character on line 106 col 4: expected "9278", got "9271"

Test 4

Group: 4

Verdict:

input
1000
818435896335669158 98300938101...

correct output
164737893
96015818
103821980
402263734
52636276
...

user output
164737893
96015818
103821980
402263734
52636276
...

Feedback: Incorrect character on line 14 col 1: expected "2", got "0"

Test 5

Group: 1, 2, 3, 4

Verdict: ACCEPTED

input
990
1 1
1 2
1 3
1 4
...

correct output
0
0
0
0
0
...

user output
0
0
0
0
0
...

Test 6

Group: 4

Verdict:

input
961
1 1000000000000000000
1 999999999999999999
1 999999999999999998
1 999999999999999997
...

correct output
1001000097
1001000097
1001000096
1001000096
1001000096
...

user output
1000998999
1000998999
1000998998
1000998998
1000998998
...

Feedback: Incorrect character on line 1 col 4: expected "1001000097", got "1000998999"