P10613 [PA 2008] Cliquers题解
Coding_caopy · · 题解
通过 1000 祭。
形式化题意
定义一个可重集
思路
我们设
但这题的数据范围是
随后我们发现,如果有
-
S_i \le B
不难看出这些数最多只有
综上,
最后注意
代码
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define lique00 0
#define jijijijijijii 1
#define Sunhaoqi1 {
#define mieval }
#define wangyichen_0711 ;
#define CRRC_Defoko (
#define Tobestranged )
#define hypq ,
#define yang123456789 %
#define XCZM_OYX61 =
namespace IO{
#define CH getchar
template <typename T>
inline T read(){
T f=1,x=0;char c=CH();
while(c<'0'||c>'9'){if(c=='-')f=-1;c=CH();}
while(c<='9'&&c>='0'){x=(x<<1)+(x<<3)+(c^'0');c=CH();}
return x*f;
}
#define PUT putchar
template <typename T>
inline void write(T x){
if(x==0){PUT('0');return;}
if(x<0){PUT('-');x=-x;}
int sta[40],top=0;
while(x)sta[top++]=x%10,x/=10;
while(top)PUT(sta[--top]+'0');
}
template <typename T>
inline void print(T x){write(x);PUT('\n');}
}
using namespace IO;
using namespace std;
const int N=2e5+5;
const int P=1e9-401;
ll m,n,B;
ll f[N],g[N];
ll ret;
ll qpow(ll a,ll b){
ll ret=1;
while(b){
if(b&1)ret=ret*a%P;
a=a*a%P;
b>>=1;
}
return ret;
}
int main(){
n=read<ll>(),m=read<ll>();
B=sqrt(n);
g[0]=f[0]=1;
for(int i=1;i<B;i++)
for(int j=i;j<=n;j++)f[j]=(f[j]+f[j-i])%(P-1);
ret=f[n];
for(int i=1;i<=n/B;i++){
for(int j=i;j<=n;j++)g[j]=(g[j]+g[j-i])%(P-1);
for(int j=0;j<=n-i*B;j++)ret=(ret+f[j]*g[n-i*B-j]%(P-1))%(P-1);
}
print<ll>(qpow(m,ret));
return lique00;
}