#abc300h. Ex - Fibonacci: Revisited
Ex - Fibonacci: Revisited
Score : points
问题陈述
我们通过以下方式定义序列 的一般项 :
$a_n = \begin{cases} 1 & (0 \leq n < K) \\ \displaystyle{\sum_{i=1}^K} a_{n-i} & (K \leq n). \\ \end{cases}$
给定一个整数 ,求满足 的所有非负整数 对应的 之和,模 。
什么是按位与(bitwise AND)?两个非负整数 和 的按位与运算 定义如下: ・当以二进制表示 时,其在 位上()的值为 ,当且仅当 和 在 位上都为 ,否则为 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
We define the general term of a sequence by:
$a_n = \begin{cases} 1 & (0 \leq n \lt K) \\ \displaystyle{\sum_{i=1}^K} a_{n-i} & (K \leq n). \\ \end{cases}$
Given an integer , find the sum, modulo , of over all non-negative integers such that . ( denotes the bitwise AND.)
What is bitwise AND? The bitwise AND of non-negative integers and , , is defined as follows.
・When is written in binary, its s place () is if s places of and are both , and otherwise.
Constraints
- and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2 6
Sample Output 1
21
and succeeding terms are . Four non-negative integers, , and , satisfy , so the answer is .
Sample Input 2
2 8
Sample Output 2
35
Sample Input 3
1 123456789
Sample Output 3
65536
Sample Input 4
300 20230429
Sample Output 4
125461938
Sample Input 5
42923 999999999558876113
Sample Output 5
300300300
update @ 2024/3/10 08:25:15