链接:https://ac.nowcoder.com/acm/contest/81596/

链接:登录—专业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

2 3 998244353

输出

复制17

17

示例2

输入

复制5000 5000 998244353

5000 5000 998244353

输出

复制2274146

2274146

主打一个简洁,主要是草稿被我弄丢了,首先0到2的m次方的数,n为容量,题目要求子序列&的结果为1,因此偶数不考虑(对于子序列的正确性而言),只计算奇数个数,二进制中m位,则有m-1次,设k为奇数个数,由于每位全是一超出范围所以奇数个数为2的k次方-1,之后枚举偶数的可能,偶数可能的个数为2的(n-k)次(因为是子数组),由于题目对顺序是没有要求的,因此只需要组合数C(k n)

即可得到算式

算出结果即可。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值