【BZOJ】【P3823】【定情信物】【题解】【线性筛逆元】

传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3823

有点意思的题目

脑子里yy不出来4维的情况……

把前三维打个表

发现0维个数好像是 2^n

然后就是 f[i]=f[i-1]*(n-i+1)/2i 筛逆元算就完了

UPD:数据加强被叉了T_T

原因是p的倍数没有逆元……

所以记录一下当前数中有多少个p就可以了

Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL n,p;
LL pw(LL x,LL k){
    LL ans=1;
    for(;k;k>>=1){
        if(k&1)ans=(ans*x)%p;
        x=(x*x)%p;
    }return ans;
}
LL f,ans;
int inv[int(2e7+5)];
int cnt=0;
int main(){
    cin>>n>>p;
    ans=f=pw(2,n);cnt=0;inv[1]=1;
    for(int i=2;i<=min(2*n,p-1);i++)inv[i]=(LL)(p-p/i)*inv[p%i]%p;
    for(int i=1;i<=n;i++){
		int tmp=n-i+1;
		while(tmp%p==0)cnt++,tmp/=p;
		f=(LL)f*tmp%p;
		tmp=2*i;
		while(tmp%p==0)cnt--,tmp/=p;
		f=(LL)f*inv[tmp%p]%p;
        ans^=cnt?0:f;
    }cout<<ans<<endl;
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值