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使得,称这个数组为羊毛数组.
求当 时,有几个数组不为羊毛数组.
思路:(注意下面N和n代表的不一含义)
没想到这题考虑异或和,一直在按位考虑,其实到现在异或的题目大部分
不是考虑异或和就是考虑按位贡献、线性基算是进阶的按位考虑了。
这题要求最终的a数组中没有任何一个字串异或和为零,那么即前缀和数组
中任意两个数异或不为零,即前缀和数组中元素两两不同,即有多少个两两元素不同
的前缀和数组,前缀和sum数组有N+1个元素,值域0~,答案本来应该是
,但是注意到我们是要通过前缀和数组
产生不同的一些a数组 ,所以前缀和的第一个元素是多余的,只要后面的不同就好了,
反正就是说后面的固定了,不管第一位怎么变化,都是一种情况。所以答案是:
。(其实前缀和不可能为零,所以第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;