QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#669051#9309. GraphFolityTL 25ms16132kbC++201.2kb2024-10-23 17:08:362024-10-23 17:08:37

Judging History

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

  • [2024-10-23 17:08:37]
  • 评测
  • 测评结果:TL
  • 用时:25ms
  • 内存:16132kb
  • [2024-10-23 17:08:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N=5e5+3,mod=998244353;
int cnt=0,pri[N];
bool np[N];
void sieve(int n){
	np[1]=1;
	for(int i=2;i<=n;++i){
		if(!np[i])pri[++cnt]=i;
		for(int j=1;j<=cnt&&i*pri[j]<=n;++j){
			np[i*pri[j]]=1;
			if(!(i%pri[j]))break;
		}
	}
}

int tot=0;
ll n,q,buc[N*2],g[N*2],i1[N],i2[N];
inline ll S(ll x){
	return x<=q?g[i1[x]]:g[i2[n/x]];
}

ll qpow(ll x,ll y){
    x%=mod,y%=mod-1;
    ll r=1;
    for(;y;y>>=1){
        if(y&1)r=r*x%mod;
        x=x*x%mod;
    }
    return r;
}

int main(){
	cin>>n;
	q=sqrt(n);
	sieve(q);
	for(ll i=1,j;i<=n;i=j+1){
		j=n/(n/i);
		buc[++tot]=n/i;
        g[tot]=buc[tot]-1;
		if(n/i<=q)i1[n/i]=tot;
		else i2[n/(n/i)]=tot;
	}
	for(int i=1;i<=cnt;++i)
		for(int j=1;j<=tot&&pri[i]*pri[i]<=buc[j];++j){
			ll t=buc[j]/pri[i];
			ll k=t<=q?i1[t]:i2[n/t];
            g[j]-=g[k]-i+1;
		}
    ll ans=1,w,t;
    for(ll i=1,j,m;i<=n/3;i=j+1){
        m=n/i,j=n/m;
        if(m==3)t=3;
        else{
            w=S(m)-S(m/2)+2;
            t=(m-w+1)%mod*qpow(m,w-2)%mod;
        }
        ans=ans*qpow(t,j-i+1)%mod;
    }
    cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 13892kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 2ms
memory: 11860kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 2ms
memory: 11796kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 3ms
memory: 13776kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 3ms
memory: 13920kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

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

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 25ms
memory: 12088kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Time Limit Exceeded

input:

5120103302

output:


result: