Codeforces Round #148 (Div. 2) C. Not Wool Sequences(前缀异或和)

C. Not Wool Sequences

A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if

and only if there exists two integers l and r(1 ≤ l ≤ r ≤ n) such that .

In other words each wool sequence contains a subsequence of consecutive elements with xor

equal to 0.

The expression  means applying the operation of a bitwise xor to numbers x and y.

The given operation exists in all modern programming languages, for example, in languages 

C++ and Java it is marked as "^", in Pascal — as "xor".

In this problem you are asked to compute the number of sequences made of n integers from

0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9).

Input

The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).

Output

Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.

Examples

input

3 2

output

6

Note

Sequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are 

(1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).

题意:

如果有一个数组a1~an,存在一对l,r使得a_{l}\otimes a_{l+1}\otimes ...\otimes a_{r}=0,称这个数组为羊毛数组.

求当0<=ai<=2^n 时,有几个数组不为羊毛数组.

思路:(注意下面N和n代表的不一含义)

         没想到这题考虑异或和,一直在按位考虑,其实到现在异或的题目大部分

不是考虑异或和就是考虑按位贡献、线性基算是进阶的按位考虑了。

         这题要求最终的a数组中没有任何一个字串异或和为零,那么即前缀和数组

中任意两个数异或不为零,即前缀和数组中元素两两不同,即有多少个两两元素不同

的前缀和数组,前缀和sum数组有N+1个元素,值域0~2^n-1,答案本来应该是

2^n*(2^n-1)*(2^n-2)*......*(2^n-n),但是注意到我们是要通过前缀和数组

产生不同的一些a数组 ,所以前缀和的第一个元素是多余的,只要后面的不同就好了,

反正就是说后面的固定了,不管第一位怎么变化,都是一种情况。所以答案是:

(2^n-1)*(2^n-2)*......*(2^n-n)。(其实前缀和不可能为零,所以第0位

前缀和直接固定为0即可)

代码实现:

没必要快速幂,只是熟悉一下。。。

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<cstdio>
#include<algorithm>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=2e5+100;
const int M=4e4+100;
const  int mod=1e9+9;
LL mypow(LL x,LL y){
	LL base=x,ans=1;
	while(y){
		if(y&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		y>>=1;
	}
	return ans%mod;
}
int main(){
	
	int n,m;
	LL ans;
	while(cin>>n>>m){
		ans=1;
		LL up=mypow(2,m);
		for(int i=1;i<=n;i++){
			ans=(ans*(up-(LL)i)%mod)%mod;
		}
		cout<<ans<<endl;
	}
	return 0;
	
}

THE END;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值