2024牛客多校:A.Bit Common

链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
 

题目描述

Given two integers nnn and mmm, among all the sequences containing nnn non-negative integers less than 2m2^m2m, you need to count the number of such sequences AAA that there exists a non-empty subsequence of AAA in which the bitwise AND of the integers is 111.

Note that a non-empty subsequence of a sequence AAA is a non-empty sequence that can be obtained by deleting zero or more elements from AAA and arranging the remaining elements in their original order.

Since the answer may be very large, output it modulo a positive integer qqq.

The bitwise AND of non-negative integers AAA and BBB, A AND BA\ \texttt{AND}\ BA AND B is defined as follows:

  • When A AND BA\ \texttt{AND}\ BA AND B is written in base two, the digit in the 2d2^d2d's place (d≥0d \ge 0d≥0) is 111 if those of AAA and BBB are both 111, and 000 otherwise.

For example, we have 4 AND 64\ \texttt{AND}\ 64 AND 6 = 444 (in base two: 100 AND 110100\ \texttt{AND}\ 110100 AND 110 = 100100100).

Generally, the bitwise AND of kkk non-negative integers p1,p2,…,pkp_1, p_2, \ldots, p_kp1​,p2​,…,pk​ is defined as
(…((p1 AND p2) AND p3) AND … AND pk)(\ldots((p_1\ \texttt{AND}\ p_2)\ \texttt{AND}\ p_3)\ \texttt{AND}\ \ldots\ \texttt{AND}\ p_k)(…((p1​ AND p2​) AND p3​) AND … AND pk​)
and we can prove that this value does not depend on the order of p1,p2,…,pkp_1, p_2, \ldots, p_kp1​,p2​,…,pk​.

输入描述:

The only line contains three integers nnn (1≤n≤5 0001 \le n \le 5\,0001≤n≤5000), mmm (1≤m≤5 0001 \le m \le 5\,0001≤m≤5000) and qqq (1≤q≤1091 \le q \le 10^91≤q≤109).

输出描述:

Output a line containing an integer, denoting the answer.

示例1

输入

2 3 998244353

输出

17

#include<bits/stdc++.h>
using namespace std;
#define int  int long long
int q,n,m;
int C[5050][5050];
void init(){//组合数 
    for(int i=1;i<=n;i++)
        C[i][1]=i%q;
    for(int i=2;i<=n;i++)
        for(int j=2;j<=i;j++)
            C[i][j]=(C[i-1][j]+C[i-1][j-1])%q;
}
int po(int a,int b){//快速幂 
	int sum=1;
	while(b){
		if(b&1)sum=sum*a%q;
		a=a*a%q;
		b>>=1;
	}
	return sum;
}
signed main(){
	cin>>n>>m>>q;
	init();
	int ans=0ll;
	for(int i=1;i<=n;i++){
		ans+=C[n][i]*po(2,(n-i)*(m-1ll))%q*po((po(2ll,i)-1ll)%q,m-1ll);//公式 
		ans%=q;
	}	
	cout<<ans<<endl;
	return 0;
} 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值