A15505 | Carry Bit
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let $f(x,y)$ be the number of carries of $x+y$ in binary (i. e. $f(x,y)=g(x)+g(y)-g(x+y)$ , where $g(x)$ is the number of ones in the binary representation of $x$ ).
Given two integers $n$ and $k$ , find the number of ordered pairs $(a,b)$ such that $0 \leq a,b < 2^n$ , and $f(a,b)$ equals $k$ . Note that for $a\ne b$ , $(a,b)$ and $(b,a)$ are considered as two different pairs.
As this number may be large, output it modulo $10^9+7$ .
Given two integers $n$ and $k$ , find the number of ordered pairs $(a,b)$ such that $0 \leq a,b < 2^n$ , and $f(a,b)$ equals $k$ . Note that for $a\ne b$ , $(a,b)$ and $(b,a)$ are considered as two different pairs.
As this number may be large, output it modulo $10^9+7$ .
输入格式
The only line of each test contains two integers $n$ and $k$ ( $0\leq k<n\leq 10^6$ ).
输出格式
Output a single integer — the answer modulo $10^9+7$ .
输入输出样例
输入 #1
3 1
输出 #1
15
输入 #2
3 0
输出 #2
27
输入 #3
998 244
输出 #3
573035660
Here are some examples for understanding carries:
$$ \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)=1$ , $f(5,1)=1$ and $f(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)$.
$$ \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)=1$ , $f(5,1)=1$ and $f(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)$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted