QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#566711#9309. Graph2016gdgzoi471AC ✓296ms25492kbC++141.5kb2024-09-16 01:17:492024-09-16 01:17:54

Judging History

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

  • [2024-09-16 01:17:54]
  • 评测
  • 测评结果:AC
  • 用时:296ms
  • 内存:25492kb
  • [2024-09-16 01:17:49]
  • 提交

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%mod,j-2),nxt-i+1)%mod;
			}
		}else{
        	ans=1LL*ans*fastpow(1LL*fastpow(j%mod,vf-1)*((j-vf)%mod)%mod,nxt-i+1)%mod;
		}
//        printf("%lld\n",ans);
    }
    printf("%d\n",ans);
    return 0;
}

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

詳細信息

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 6ms
memory: 14268kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 16ms
memory: 10792kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

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

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 42ms
memory: 18732kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 98ms
memory: 17792kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 185ms
memory: 23084kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 263ms
memory: 24688kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 295ms
memory: 24792kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 296ms
memory: 24744kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 296ms
memory: 25492kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed