1930E - 234 Wonderful Wonderful - CodeForces Solution


combinatorics math

Please click on ads to support us..

C++ Code:

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

typedef long long ll;
const int mod=998244353,N=1e6+100,maxn=1e6;
int fl[N],nf[N];

int mi(int x,int t){
	int d=1;
	while(t){
		if(t%2) d=(ll)d*x%mod;
		x=(ll)x*x%mod;t/=2;
	}
	return d;
}
int ni(int x) {return mi(x,mod-2);}

int C(int n,int m){
	if(m<0||m>n) return 0;
	return (ll)fl[n]*nf[m]%mod*nf[n-m]%mod;
}

int main()
{
	
	fl[0]=1;for(int i=1;i<=maxn;i++) fl[i]=(ll)fl[i-1]*i%mod;
	nf[maxn]=ni(fl[maxn]);for(int i=maxn-1;i>=0;i--) nf[i]=(ll)nf[i+1]*(i+1)%mod;
	
	int T;scanf("%d",&T);
	while(T--){
		int n;scanf("%d",&n);
		
		for(int i=1;i<=(n-1)/2;i++){
			int Sum=1;
			for(int j=i*2;j<=n;j+=i*2)
				Sum=(Sum+C(n,j))%mod;
				
			for(int len=2;len<=n;len=len+i*2) Sum=(Sum-C(n-len+1,2*(i-1)+1)+mod)%mod;
			/*for(int j=1;j<=n;j++)
				for(int k=j;k<=n;k++)
					if((k-j+1+(i-1)*2)%(i*2)==0){
						int tmp=(ll)C(j-1,i-1)*C(n-k,i-1)%mod;
						C(j-1,j-i) n-k,i-1
						n-k+j-1,j-1
						n-len
						Sum=(Sum-tmp+mod)%mod;
					}*/
			printf("%d ",Sum);
		}
		printf("\n");
	}
	
	return 0;
}


Comments

Submit
0 Comments
More Questions

361A - Levko and Table
5E - Bindian Signalizing
687A - NP-Hard Problem
1542C - Strange Function
961E - Tufurama
129D - String
888A - Local Extrema
722B - Verse Pattern
278A - Circle Line
940A - Points on the line
1742C - Stripes
1742F - Smaller
1742B - Increasing
1742A - Sum
1742D - Coprime
390A - Inna and Alarm Clock
1398B - Substring Removal Game
1742G - Orray
416B - Art Union
962A - Equator
803B - Distances to Zero
291A - Spyke Talks
1742E - Scuza
1506D - Epic Transformation
1354G - Find a Gift
1426F - Number of Subsequences
1146B - Hate "A"
1718C - Tonya and Burenka-179
834A - The Useless Toy
1407D - Discrete Centrifugal Jumps