QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602199#9309. GraphlaurxhAC ✓315ms48184kbC++141.5kb2024-09-30 20:54:582024-09-30 20:55:06

Judging History

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

  • [2024-09-30 20:55:06]
  • 评测
  • 测评结果:AC
  • 用时:315ms
  • 内存:48184kb
  • [2024-09-30 20:54:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e6+7;
const int mod=998244353;
ll n,tot,cnt,len;
int vis[N],prime[N];
ll g[N],w[N],idx1[N],idx2[N];
void seive(){
    for(int i=2;i<N;i++){
        if(!vis[i])prime[++tot]=i;
        for(int j=1;j<=tot&&1ll*i*prime[j]<N;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j]==0)break;
        }
    }
}
ll kuasum(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        b>>=1;
        a=a*a%mod;
    }
    return ans;
}
ll get_id(ll x){
    return (x<=len?idx1[x]:idx2[n/x]);
}
ll get(ll x){
    return g[get_id(x)];
}
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 
    seive();
    cin>>n;
    len=sqrt(n);
    for(ll l=1,r;l<=n;l=r+1){
        r=n/(n/l);ll x=n/l;w[++cnt]=x;
        g[cnt]=x-1; 
        if(w[cnt]<=len)idx1[w[cnt]]=cnt;
        else idx2[n/w[cnt]]=cnt;     
    }
    for(int i=1;i<=tot;i++){
        for(int j=1;j<=cnt&&1ll*prime[i]*prime[i]<=w[j];j++){
            ll x=prime[i],r=w[j]/x;
            int k=get_id(r);
            g[j]-=g[k]-(i-1);
        }
    }
    ll ans=1;
    for(ll l=1,r;l<=n;l=r+1){
        ll x=n/l;
        r=n/x;
        if(x==1)continue;
        ll sum=get(x)-get(x/2)+1;
        ll num=sum+(x!=sum);
        ll res=kuasum(x%mod,num-2);
        if(x!=sum)res=res*((x-sum)%mod)%mod;
        // cout<<sum<<" "<<res<<"\n";
        ans=ans*kuasum(res,r-l+1)%mod;
    }  
    cout<<ans<<"\n";
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 15ms
memory: 33360kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 21ms
memory: 33360kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 18ms
memory: 33452kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 18ms
memory: 31380kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 21ms
memory: 31392kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 18ms
memory: 33412kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 18ms
memory: 31328kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 33ms
memory: 33668kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 30ms
memory: 35612kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 43ms
memory: 35836kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 61ms
memory: 38076kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 119ms
memory: 38556kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 209ms
memory: 41976kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 277ms
memory: 47408kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

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

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

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

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

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

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed