QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#591256#9309. GrapheastcloudWA 406ms23160kbC++205.3kb2024-09-26 14:59:232024-09-26 14:59:23

Judging History

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

  • [2024-09-26 14:59:23]
  • 评测
  • 测评结果:WA
  • 用时:406ms
  • 内存:23160kb
  • [2024-09-26 14:59:23]
  • 提交

answer


#include<bits/stdc++.h>

#define ll long long
#define pi pair<int,int>
#define vi vector<int>
#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(int x){
    if(x<0)x=-x,putchar('-');
    if(x/10)write(x/10);
    putchar(x%10+'0');
}

namespace phi{
    int qp(int x,int y){int 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;
        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];
    }
}

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


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

int 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();

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

详细

Test #1:

score: 100
Accepted
time: 11ms
memory: 21664kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 9ms
memory: 20736kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 9ms
memory: 20368kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 9ms
memory: 20656kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 9ms
memory: 20684kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 86ms
memory: 21368kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 170ms
memory: 20868kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 406ms
memory: 23160kb

input:

5120103302

output:

384994873

result:

wrong answer expected '116870489', found '384994873'