loj #6247. 九个太阳 k次单位根 神仙构造 FFT求和原理

LINK:九个太阳

不可做系列.

构造比较神仙.

考虑FFT的求和原理有 \(\frac{1}{k}\sum_{j=0}^{k-1}(w_k^j)^n=[k|n]\)

带入这道题的式子.

\(\sum_{i=0}^n\frac{1}{k}\sum_{j=0}^{k-1}(w_k^j)^iC(n,i)\)

颠倒求和符号 二项式定理合并即可klogn求.

k次单位根在mod 998244353时就是 \(\frac{mod-1}{k}\)

code
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<queue>
#include<deque>
#include<stack>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define inf 100000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x);
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define gi(x) scanf("%lf",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define rep(p,n,i) for(RE ll i=p;i<=n;++i)
#define go(x) for(ll i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE ll i=n;i>=p;--i)
#define vep(p,n,i) for(RE ll i=p;i<n;++i)
#define pii pair<ll,ll>
#define mk make_pair
#define RE register
#define P 1000000007ll
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define EPS 1e-10
#define sq sqrt
#define S second
#define F first
#define mod 998244353
#define id(i,j) ((i-1)*m+j)
#define max(x,y) ((x)<(y)?y:x)
#define a(i) t[i].a
#define b(i) t[i].b
using namespace std;
char *fs,*ft,buf[1<<15];
inline char gc()
{
	return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline ll read()
{
	RE ll x=0,f=1;RE char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=gc();}
	return x*f;
}
//我心裏住着一位天使 我怎能可以讓她沒有翅膀?
const ll G=3;
ll n,k;
inline ll ksm(ll b,ll p)
{
	ll cnt=1;p=p%(mod-1);
	while(p)
	{
		if(p&1)cnt=(ll)cnt*b%mod;
		p=p>>1;b=(ll)b*b%mod;
	}
	return cnt;
}
signed main()
{
	freopen("1.in","r",stdin);
	get(n);get(k);
	ll ans=0;
	ll wn=ksm(G,(mod-1)/k),cc=1;
	rep(0,k-1,i)
	{
		ans=(ans+ksm(cc+1,n))%mod;
		cc=(ll)cc*wn%mod;
	}
	put(ans*(ll)ksm(k,mod-2)%mod);
	return 0;
}
posted @ 2020-07-30 21:42  chdy  阅读(214)  评论(0编辑  收藏  举报