QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186244#6740. FunctionUrgantTeam#RE 15ms4228kbC++233.0kb2023-09-23 15:20:022023-09-23 15:20:03

Judging History

你现在查看的是最新测评结果

  • [2023-09-23 15:20:03]
  • 评测
  • 测评结果:RE
  • 用时:15ms
  • 内存:4228kb
  • [2023-09-23 15:20:02]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cmath>

#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long double ld;
typedef long long ll;
using vi = vector<int>;
using vl = vector<ll>;

const int C = 20210926;
const int D = 100000;

int get_min_prime(const int n) {
    static vi mnp;
    static vi primes;
    if (mnp.empty()) {
        mnp.resize(D + 1, 1);
        for (int i = 2; i <= D; ++i) {
            if (mnp[i] == 1) {
                mnp[i] = i;
                primes.push_back(i);
            }
            for (int j : primes) {
                if (j > mnp[i]) break;
                int prod = j * i;
                if (prod > D) break;
                mnp[prod] = j;
            }
        }
    }
    return mnp[n];
}

vi get_divisors(int n) {
    if (n == 1) return {1};
    int p = get_min_prime(n);
    int a = 0;
    while (n % p == 0) {
        n /= p;
        ++a;
    }
    vi dvs = get_divisors(n);
    const int dvss = dvs.size();
    for (int i = 0; i < dvss * a; ++i)
        dvs.push_back(dvs[i] * p);
    return dvs;
}

const int M = 998244353;
int sum(int a, int b, int m = M) {
    if ((a += b) >= m)
        a -= m;
    return a;
}
int dif(int a, int b, int m = M) {
    if ((a -= b) < 0)
        a += m;
    return a;
}
int prod(int a, int b, int m = M) {
    return ((ll)a * b) % m;
}

int find_f(const int n) {
    static vi v;
    if (v.empty()) {
        v.resize(D + 1);
        for (int i = 1; i <= D; ++i) {
            v[i] = sum(1, v[i - 1]);
            for (int d : get_divisors(i))
                if (d != 1 && d != i)
                    v[i] = sum(v[i], dif(v[d], v[d - 1]));
        }
    }
    return v[n];
}

int find_ans(const int n) {
    if (n <= D)
        return find_f(n);
    int max_m = n / (D + 1);
    vi ans(max_m + 1);
    for (int m = max_m; m >= 1; --m) {
        const int N = n / m;
        ans[m] = 1;
        const int MAX_I = min(C, max_m / m);
        for (int i = 2; i <= MAX_I; ++i)
            ans[m] = sum(ans[m], ans[m * i]);
        const int U = max(int(sqrtf(n)) / m, MAX_I);
        for (int i = MAX_I + 1; i <= U; ++i)
            ans[m] = sum(ans[m], find_f(N / i));
        for (int j = N / C; j <= N / (U + 1); ++j) {
            ll f = find_f(j);
            int L = U + 1;
            int R1 = min(C, N / j);
            int R2 = min(C, N / (j + 1));
            int qua1 = max(0, R1 - L + 1);
            int qua2 = max(0, R2 - L + 1);
            int qua = qua1 - qua2;
            ans[m] = sum(ans[m], prod(f, qua));
        }
    }
    return ans[1];
}

bool solve_test() {
    int n;
    if (!(cin >> n)) return false;
    cout << find_ans(n) << '\n';
    return true;
}

void solve_tests() {
    while (solve_test());
}

int main() {
#ifdef HOME
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    solve_tests();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 15ms
memory: 4172kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 14ms
memory: 4120kb

input:

2

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 14ms
memory: 4172kb

input:

100

output:

949

result:

ok 1 number(s): "949"

Test #4:

score: 0
Accepted
time: 14ms
memory: 4228kb

input:

10

output:

19

result:

ok 1 number(s): "19"

Test #5:

score: 0
Accepted
time: 10ms
memory: 4124kb

input:

1000

output:

48614

result:

ok 1 number(s): "48614"

Test #6:

score: 0
Accepted
time: 14ms
memory: 4148kb

input:

10000

output:

2602393

result:

ok 1 number(s): "2602393"

Test #7:

score: 0
Accepted
time: 14ms
memory: 4120kb

input:

100000

output:

139804054

result:

ok 1 number(s): "139804054"

Test #8:

score: -100
Runtime Error

input:

1000000

output:


result: