CF1761D.Carry Bit

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let f(x,y)f(x,y) be the number of carries of x+yx+y in binary (i. e. f(x,y)=g(x)+g(y)g(x+y)f(x,y)=g(x)+g(y)-g(x+y) , where g(x)g(x) is the number of ones in the binary representation of xx ).

Given two integers nn and kk , find the number of ordered pairs (a,b)(a,b) such that 0a,b<2n0 \leq a,b < 2^n , and f(a,b)f(a,b) equals kk . Note that for aba\ne b , (a,b)(a,b) and (b,a)(b,a) are considered as two different pairs.

As this number may be large, output it modulo 109+710^9+7 .

输入格式

The only line of each test contains two integers nn and kk ( 0k<n1060\leq k<n\leq 10^6 ).

输出格式

Output a single integer — the answer modulo 109+710^9+7 .

输入输出样例

  • 输入#1

    3 1

    输出#1

    15
  • 输入#2

    3 0

    输出#2

    27
  • 输入#3

    998 244

    输出#3

    573035660

说明/提示

Here are some examples for understanding carries:

1  1  1+ 11  0  0 1  0  1  1 1  0  1+   0  011 0  1  1  0 1  0  1+ 101111 1  0  0  0\begin{aligned} &\begin{array}{r} 1_{\ \ }1_{\ \ }1\\ +\ _{1}1_{\ \ }0_{\ \ }0\\ \hline \ 1_{\ \ }0_{\ \ }1_{\ \ }1 \end{array} &\begin{array}{r} \ 1_{\ \ }0_{\ \ }1\\ +\ _{\ \ }0_{\ \ }0_{1}1\\ \hline \ 0_{\ \ }1_{\ \ }1_{\ \ }0 \end{array} & &\begin{array}{r} \ 1_{\ \ }0_{\ \ }1\\ +\ _{1}0_{1}1_{1}1\\ \hline \ 1_{\ \ }0_{\ \ }0_{\ \ }0 \end{array} \end{aligned}

So f(7,4)=1f(7,4)=1 , f(5,1)=1f(5,1)=1 and f(5,3)=3f(5,3)=3 .

In the first test case, all the pairs meeting the constraints are (1,1),(1,5),(2,2),(2,3),(3,2),(4,4),(4,5),(4,6),(4,7),(5,1),(5,4),(5,6),(6,4),(6,5),(7,4)(1,1),(1,5),(2,2),(2,3),(3,2),(4,4),(4,5),(4,6),(4,7),(5,1),(5,4),(5,6),(6,4),(6,5),(7,4).

首页