QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591510#9309. GrapheastcloudAC ✓2573ms663680kbC++205.2kb2024-09-26 16:15:092024-09-26 16:15:10

Judging History

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

  • [2024-09-26 16:15:10]
  • 评测
  • 测评结果:AC
  • 用时:2573ms
  • 内存:663680kb
  • [2024-09-26 16:15:09]
  • 提交

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 M 40000005
ll vis[M],cnt,sum[M],pri[M];
void prework(){
    for(ll i=2;i<M;i++){
        if(!vis[i])pri[++cnt]=i,sum[i]++;
        for(ll j=1;j<=cnt && pri[j]*i<M;j++){
            vis[i*pri[j]]++;
            if(i%pri[j]==0)break;
        }
    }
    for(ll i=1;i<M;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<M)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%mod,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;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 282ms
memory: 650300kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 298ms
memory: 650284kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 297ms
memory: 650296kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 255ms
memory: 650452kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 278ms
memory: 650292kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 282ms
memory: 650092kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 299ms
memory: 650364kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 291ms
memory: 650440kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 267ms
memory: 648388kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 289ms
memory: 648244kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 268ms
memory: 648728kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 303ms
memory: 651408kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 324ms
memory: 649228kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 315ms
memory: 651932kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 402ms
memory: 652932kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 722ms
memory: 655800kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 1485ms
memory: 659716kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 2213ms
memory: 662408kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 2561ms
memory: 663660kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 2573ms
memory: 663680kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 2562ms
memory: 661656kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed