QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#570607#9309. GraphlprdsbTL 1512ms672020kbC++144.4kb2024-09-17 16:43:072024-09-17 16:43:08

Judging History

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

  • [2024-09-17 16:43:08]
  • 评测
  • 测评结果:TL
  • 用时:1512ms
  • 内存:672020kb
  • [2024-09-17 16:43:07]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i, a, b) for(LL i = (a), en = (b); i <= en; ++i)
#define Rof(i, a, b) for(LL i = (a), en = (b); i >= en; --i)
#define Tra(u, i) for(int i = hd[u]; ~i; i = e[i].net)
#define cst const
#define LL long long
#define DD double
#define LD long double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define inf 0x3f3f3f3f
#define Inf 0x3f3f3f3f3f3f3f3f
#define eps 1e-12
#define maxn 1000000
using namespace std;

LL pri[maxn + 5], cnt = 0, vis[maxn + 5];

template<class T>
T fp(T x, LL y) {
    T asi = 1;
    while(y) {
        if(y & 1) asi *= x;
        x *= x;
        y >>= 1;
    }
    return asi;
}

template<int P>
struct Mint {
    int x;
    Mint() { x = 0; }
    Mint(LL _x) : x{ norm(_x % P) } {}
    int norm(LL _x) {
        if(_x < 0) _x += P;
        if(_x >= P) _x -= P;
        return _x;
    }
    Mint inv() { return fp(*this, P - 2); }
    Mint operator - () { return { P - x }; }
    Mint& operator += (Mint _x) & {
        x = norm(x + _x.x);
        return *this;
    }
    Mint& operator -= (Mint _x) & {
        x = norm(x - _x.x);
        return *this;
    }
    Mint& operator *= (Mint _x) & {
        x = 1ll * x * _x.x % P;
        return *this;
    }
    Mint& operator /= (Mint _x) & { return *this *= _x.inv(); }
    friend Mint operator + (Mint _x, Mint _y) { return _x += _y; }
    friend Mint operator - (Mint _x, Mint _y) { return _x -= _y; }
    friend Mint operator * (Mint _x, Mint _y) { return _x *= _y; }
    friend Mint operator / (Mint _x, Mint _y) { return _x /= _y; }
    friend bool operator == (Mint _x, Mint _y) { return _x.x == _y.x; }
};

const int P = 998244353;
using Z = Mint<P>;

class Sieve {
    public:
    LL to[maxn + 5], tot = 0, k_n[maxn + 5];
    LL N;
    LL sum_f_p[maxn + 5];
    unordered_map<int, int> id;
    vector<int> vG[maxn + 5];
    vector<LL> G[maxn + 5];
    LL get_g(LL x) {
        //
        return 1;
    }
    Sieve() {}
    LL get_G(int n_id, int k) {
        if(pri[k] > to[n_id]) return get_g(1);
        if(k == 1) return to[n_id];
        if(1ll * pri[k - 1] * pri[k - 1] > to[n_id]) return get_G(n_id, k_n[n_id] + 1) - (sum_f_p[k - 1] - sum_f_p[k_n[n_id]]);
        return G[n_id][k];
        // cout << n_id << " " << k << " " << 1ll * pri[k - 1] * pri[k - 1] << " " << to[n_id] << endl;
    }
    void init(LL _N) {
        N = _N;
        tot = 0;
        For(i, 1, N) {
            ++tot;
            id[to[tot] = N / i] = tot;
            i = N / (N / i);
        }
        int now = cnt;
        For(i, 1, tot) {
            while(1ll * pri[now] * pri[now] > to[i]) now--;
            G[i].clear();
            G[i].resize(now + 5, 0);
            vG[i].clear();
            vG[i].resize(now + 5, 0);
            k_n[i] = now;
        }
        For(i, 1, cnt) sum_f_p[i] = sum_f_p[i - 1] + get_g(pri[i]);
        For(i, 2, k_n[1] + 1) {
            For(j, 1, tot) {
                if(1ll * pri[i - 1] * pri[i - 1] > to[j]) break;
                vG[j][i] = 1;
                G[j][i] = get_G(j, i - 1) - get_g(pri[i - 1]) * get_G(id[to[j] / pri[i - 1]], i - 1);
                // if(j == 1) cout << i << endl;
            }
        }
    }
    LL get_s(LL n) {
        // cout << k_n[n] << endl;
        return k_n[id[n]] + get_G(id[n], k_n[id[n]] + 1);
    }
} sieve[2];

template <class T>
void read(T &x) {
    char ch;
    bool ok;
    for(ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if(ch == '-') ok = 1;
    for(x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
    if(ok) x = -x;
}

int main() {
    // freopen("in.txt", "r", stdin);
    For(i, 2, maxn) {
        if(!vis[i]) pri[++cnt] = i;
        for(int j = 1; j <= cnt && i * pri[j] <= maxn; ++j) {
            vis[i * pri[j]] = 1;
            if(i % pri[j] == 0) break;
        }
    }
    LL n = 4;
    read(n);
    sieve[0].init(n); sieve[1].init(n / 2);
    Z res = 1;
    for(LL i = 1; i <= n; ++i) {
        LL now = n / i, to = n / now;
        if(now <= 2) break;
        LL cntp = sieve[0].get_s(now) - sieve[1].get_s(now / 2);
        LL cnt = cntp + 1 + (now - cntp - 1 != 0);
        // cout << now << " " << tmp << " " << sieve[0].get_s(now) - sieve[1].get_s(now / 2) << endl;
        res *= fp(fp(Z{ now }, cnt - 2) * Z { (now - cntp - 1) ? (now - cntp - 1) : 1 }, to - i + 1);
        i = to;
    }
    cout << res.x << endl;
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 12ms
memory: 119592kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 19ms
memory: 118252kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 11ms
memory: 120364kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 19ms
memory: 120176kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 19ms
memory: 119876kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 12ms
memory: 118228kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 15ms
memory: 118772kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 15ms
memory: 115976kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 19ms
memory: 120856kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 22ms
memory: 123820kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 42ms
memory: 135908kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 131ms
memory: 190480kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 144ms
memory: 189420kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 252ms
memory: 237640kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 505ms
memory: 338980kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 1512ms
memory: 672020kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: -100
Time Limit Exceeded

input:

52500109238

output:

195086665

result: