QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566696#9309. Graph2016gdgzoi471WA 38ms15288kbC++141.5kb2024-09-16 01:13:552024-09-16 01:13:55

Judging History

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

  • [2024-09-16 01:13:55]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:15288kb
  • [2024-09-16 01:13:55]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long ll;
const int N=1000005;
ll n,w[N],g[N];
int sq,tot,m,p[N],id1[N],id2[N];
bool vis[N];
void init(){
	sq=sqrt(n);
	for(int i=2;i<=sq;i++){	
		if(!vis[i]){
			p[++tot]=i;
		}
		for(int j=1;j<=tot&&i*p[j]<=sq;j++){
			vis[i*p[j]]=true;
			if(i%p[j]==0){
				break;
			}
		}
	}
	for(ll i=1,nxt;i<=n;i=nxt+1){
		nxt=n/(n/i);
		w[++m]=n/i;
		if(w[m]<=sq){
			id1[w[m]]=m;
		}else{
			id2[n/w[m]]=m;
		}
		g[m]=w[m]-1;
	}
	for(int j=1;j<=tot;j++){
		ll sqr=1LL*p[j]*p[j];
		for(int i=1;i<=m&&w[i]>=sqr;i++){
			ll tmp=w[i]/p[j];
			tmp=tmp<=sq?id1[tmp]:id2[n/tmp];
			g[i]-=g[tmp]-j+1;
		}
	}
}
const int mod=998244353;
int fastpow(int a,ll x){
    int res=1;
    while(x){
        if(x&1){
            res=1LL*res*a%mod;
        }
        x>>=1;
        a=1LL*a*a%mod;
    }
    return res;
}
int P(ll x){
	return x<=sq?g[id1[x]]:g[id2[n/x]];
}
ll F(ll x){
    return P(n/x)-P(n/x/2)+1;
}
int main(){
    scanf("%lld",&n);
    if(n<=2){
        puts("1");
        return 0;
    }
    init();
    int ans=1;
    for(ll i=1,j,nxt;i<=n;i=nxt+1){
        j=n/i,nxt=n/j;
        ll vf=F(i);
//        printf("%lld %lld\n",i,vf);
        if(vf==j){
        	if(j>1){
        		ans=1LL*ans*fastpow(fastpow(j,j-2),nxt-i+1)%mod;
			}
		}else{
        	ans=1LL*ans*fastpow(1LL*fastpow(j,vf-1)*(j-vf)%mod,nxt-i+1)%mod;
		}
//        printf("%lld\n",ans);
    }
    printf("%d\n",ans);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 10056kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 5ms
memory: 12228kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

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

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 20ms
memory: 14608kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 38ms
memory: 15288kb

input:

5120103302

output:

384994873

result:

wrong answer expected '116870489', found '384994873'