QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#568477#9309. GraphwyxqwqTL 1903ms5248kbC++144.0kb2024-09-16 16:41:192024-09-16 16:41:20

Judging History

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

  • [2024-09-16 16:41:20]
  • 评测
  • 测评结果:TL
  • 用时:1903ms
  • 内存:5248kb
  • [2024-09-16 16:41:19]
  • 提交

answer

#include<bits/stdc++.h>
#define re return
#define ll long long
#define fo(i,x,y) for(int i=x;i<=y;++i)
#define go(i,x,y) for(int i=x;i>=y;--i)
using namespace std;
int read(){
    int res=0,zf=1;char ch;
    while((ch=getchar())<48||ch>57)if(ch=='-')zf=!zf;res=(ch^48);
    while((ch=getchar())>=48&&ch<=57)res=(res<<3)+(res<<1)+(ch^48);
    return zf?res:(-res);
}

const int mod=998244353;
#define pro(x,y) (int)((ll)(x)*(y)%mod)
#define mul(x,y) x=pro(x,y)
int ksm(int x,ll y){
    int ret=1;
    while(y){
        if(y&1) mul(ret,x);
        mul(x,x);
        y>>=1;
    }
    re ret;
}

namespace Prime{
using i64 = long long;
i64 PI(i64 N) {
    if(N <= 1) return 0;
    int v = sqrt(N + 0.5);
    int n_4 = sqrt(v + 0.5);
    int T = min((int)sqrt(n_4) * 2, n_4);
    int K = pow(N, 0.625) / log(N) * 2;
    K = max(K, v);
    K = min<i64>(K, N);
    int B = N / K;
    B = N / (N / B);
    B = min<i64>(N / (N / B), K);

    vector<i64> l(v + 1);
    vector<int> s(K + 1);
    vector<bool> e(K + 1);
    vector<int> w(K + 1);
    for (int i = 1; i <= v; ++i) l[i] = N / i - 1;
    for (int i = 1; i <= v; ++i) s[i] = i - 1;

    const auto div = [] (i64 n, int d) -> int { return double(n) / d; };
    int p;
    for (p = 2; p <= T; ++p) 
        if (s[p] != s[p - 1]) {
            i64 M = N / p;
            int t = v / p, t0 = s[p - 1];
            for (int i = 1; i <= t; ++i) l[i] -= l[i * p] - t0;
            for (int i = t + 1; i <= v; ++i) l[i] -= s[div(M, i)] - t0;
            for (int i = v, j = t; j >= p; --j)
                for (int l = j * p; i >= l; --i)
                    s[i] -= s[j] - t0;
            for (int i = p * p; i <= K; i += p) e[i] = 1;
        }
    e[1] = 1;
    int cnt = 1;
    vector<int> roughs(B + 1);
    for (int i = 1; i <= B; ++i)
        if(!e[i]) roughs[cnt++] = i;
    roughs[cnt] = 0x7fffffff;
    for (int i = 1; i <= K; ++i) w[i] = e[i] + w[i - 1];
    for (int i = 1; i <= K; ++i) s[i] = w[i] - w[i - (i & -i)];

    const auto query = [&] (int x) -> int {
        int sum = x;
        while(x) sum -= s[x], x ^= x & -x;
        return sum;
    };
    const auto add = [&] (int x) -> void {
        e[x] = 1;
        while(x <= K) ++s[x], x += x & -x;
    };
    cnt = 1;
    for (; p <= n_4; ++p) 
        if(!e[p]) {
            i64 q = i64(p) * p, M = N / p;
            while(cnt < q) w[cnt] = query(cnt), cnt++;
            int t1 = B / p, t2 = min<i64>(B, M / q), t0 = query(p - 1);
            int id = 1, i = 1;
            for (; i <= t1; i = roughs[++id]) l[i] -= l[i * p] - t0;
            for (; i <= t2; i = roughs[++id]) l[i] -= query(div(M, i)) - t0;
            for (; i <= B; i = roughs[++id]) l[i] -= w[div(M, i)] - t0;
            for (int i = q; i <= K; i += p)
                if(!e[i]) add(i);
        }
    while(cnt <= v) w[cnt] = query(cnt), cnt++;

    vector<int> primes;
    primes.push_back(1);
    for (int i = 2; i <= v; ++i)
        if(!e[i]) primes.push_back(i);
    l[1] += i64(w[v] + w[n_4] - 1) * (w[v] - w[n_4]) / 2;
    for (int i = w[n_4] + 1; i <= w[B]; ++i) l[1] -= l[primes[i]];
    for (int i = w[B] + 1; i <= w[v]; ++i) l[1] -= query(N / primes[i]);
    for (int i = w[n_4] + 1; i <= w[v]; ++i) {
        int q = primes[i];
        i64 M = N / q;
        int e = w[M / q];
        if (e <= i)  break;
        l[1] += e - i;
        i64 t = 0;
        int m = w[sqrt(M + 0.5)];
        for (int k = i + 1; k <= m; ++k) t += w[div(M, primes[k])];
        l[1] += 2 * t - (i + m) * (m - i);
    }
    return l[1];
}
}
using Prime::PI;

ll h(ll x){re PI(x)-PI(x/2);}

int F(ll x){
    if(x==1) re 1;
    // printf("F(%lld)\n",x);
    ll a=h(x);
    // printf("h(%lld)=%lld\n",x,a);
    if(a+1==x) re ksm((int)(x%mod),x-2);
    re pro(ksm((int)(x%mod),a),x-a-1);
}

signed main(){
    ll n,ans=1;cin>>n;
    for(ll l=1,r=1;;){
        // printf("[%lld,%lld]\n",l,r);
        mul(ans,ksm(F(n/l),r-l+1));
        l=r+1;
        if(l>n) break;
        r=n/(n/l);
    }
    cout<<ans;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3932kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 4004kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3924kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 1ms
memory: 4028kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3876kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 4ms
memory: 4144kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 4ms
memory: 3980kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 31ms
memory: 4012kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 536ms
memory: 4264kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 539ms
memory: 4240kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 966ms
memory: 4616kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 1903ms
memory: 5248kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: -100
Time Limit Exceeded

input:

19834593299

output:


result: