QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591261#9309. GrapheastcloudWA 388ms40844kbC++205.2kb2024-09-26 15:00:212024-09-26 15:00:22

Judging History

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

  • [2024-09-26 15:00:22]
  • 评测
  • 测评结果:WA
  • 用时:388ms
  • 内存:40844kb
  • [2024-09-26 15:00:21]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<ll,ll>
#define vi vector<ll>
#define cpy(x,y,s) memcpy(x,y,sizeof(x[0])*(s))
#define mset(x,v,s) memset(x,v,sizeof(x[0])*(s))
#define all(x) begin(x),end(x)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ary array
#define IL inline

#define mod 998244353

using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0' || ch>'9')f=(ch=='-'?-1:f),ch=getchar();
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return x*f;
}
void write(ll x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

namespace phi{
    ll qp(ll x,ll y){ll ans=1;while(y){if(y&1)ans=ans*1ll*x%mod;x=x*1ll*x%mod;y>>=1;}return ans;}
    using i64 = long long;
    i64 Solve(i64 N) {
        if(N <= 1) return 0;
        ll v = sqrt(N + 0.5);
        ll n_4 = sqrt(v + 0.5);
        ll T = min((ll)sqrt(n_4) * 2, n_4);
        ll K = pow(N, 0.625) / log(N) * 2;
        K = max(K, v);
        K = min<i64>(K, N);
        ll B = N / K;
        B = N / (N / B);
        B = min<i64>(N / (N / B), K);

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

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

        const auto query = [&] (ll x) -> ll {
            ll sum = x;
            while(x) sum -= s[x], x ^= x & -x;
            return sum;
        };
        const auto add = [&] (ll 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++;
                ll t1 = B / p, t2 = min<i64>(B, M / q), t0 = query(p - 1);
                ll 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 (ll i = q; i <= K; i += p)
                    if(!e[i]) add(i);
            }
        while(cnt <= v) w[cnt] = query(cnt), cnt++;

        vector<ll> primes;
        primes.push_back(1);
        for (ll 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 (ll i = w[n_4] + 1; i <= w[B]; ++i) l[1] -= l[primes[i]];
        for (ll i = w[B] + 1; i <= w[v]; ++i) l[1] -= query(N / primes[i]);
        for (ll i = w[n_4] + 1; i <= w[v]; ++i) {
            ll q = primes[i];
            i64 M = N / q;
            ll e = w[M / q];
            if (e <= i)  break;
            l[1] += e - i;
            i64 t = 0;
            ll m = w[sqrt(M + 0.5)];
            for (ll k = i + 1; k <= m; ++k) t += w[div(M, primes[k])];
            l[1] += 2 * t - (i + m) * (m - i);
        }
        return l[1];
    }
}

IL ll pls(ll x,ll y){return (x+y>=mod?x+y-mod:x+y);}
IL ll sub(ll x,ll y){return (x-y<0?x-y+mod:x-y);}
IL void Add(ll &x,ll y){x=pls(x,y);}
IL void Dec(ll &x,ll y){x=sub(x,y);}
IL ll mul(ll x,ll y){return x*1ll*y%mod;}
IL ll qp(ll x,ll y=mod-2){ll ans=1;while(y){if(y&1)ans=mul(ans,x);x=mul(x,x);y>>=1;}return ans;}


#define N 2000005
ll vis[N],cnt,sum[N],pri[N];
void prework(){
    for(ll i=2;i<N;i++){
        if(!vis[i])pri[++cnt]=i,sum[i]++;
        for(ll j=1;j<=cnt && pri[j]*i<N;j++){
            vis[i*pri[j]]++;
            if(i%pri[j]==0)break;
        }
    }
    for(ll i=1;i<N;i++)sum[i]+=sum[i-1];
}

ll calc(ll m){
    if(m==1)return 1;
    if(m==2)return 1;
    if(m==3)return 3;
    ll siz=0;
    if(m<N)siz=sum[m]-sum[m/2];
    else siz=phi::Solve(m)-phi::Solve(m/2);
    ll Siz=(m-siz-1)%mod;
    return mul(Siz,qp(m,siz));
}

int main(){
    #ifdef EAST_CLOUD
    freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    #endif

    ll n=read();prework();

    ll Res=1;
    for(ll l=1,r=1;l<=n;){
        
        r=n/(n/l);
        ll m=(n/l);
        ll res=calc(m);
        Res=mul(Res,qp(res,r-l+1));
        l=r+1;
    }
    write(Res);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 37680kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 17ms
memory: 38292kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 8ms
memory: 37808kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 13ms
memory: 37744kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 8ms
memory: 38116kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 17ms
memory: 38208kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 6ms
memory: 38140kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 16ms
memory: 36708kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 83ms
memory: 39148kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 82ms
memory: 38916kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 177ms
memory: 39376kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 388ms
memory: 40844kb

input:

5120103302

output:

406301251

result:

wrong answer expected '116870489', found '406301251'