列表

详情


NC225351. Redundant Binary Notation

描述

    Redundant binary notation is similar to binary notation, except instead of allowing only ’s and ’s for each digit, we allow any integer digit in the range , where t is some specified upper bound. For example, if , the digit  is permitted, and we may write the decimal number  as , , or . If , every number has precisely one representation, which is its typical binary representation. In general, if a number is written as  in redundant binary notation, the equivalent decimal number is .

    Redundant binary notation can allow carryless arithmetic, and thus has applications in hardware design and even in the design of worst-case data structures. For example, consider insertion into a standard binomial heap. This operation takes  worst-case time but  amortized time. This is because the binary number representing the total number of elements in the heap can be incremented in worst-case time and amortized time. By using a redundant binary representation of the individual binomial trees in a binomial heap, it is possible to improve the worst-case insertion time of binomial heaps to .
    However, none of that information is relevant to this question. In this question, your task is simple. Given a decimal number and the digit upper bound , you are to count the number of possible representations has in redundant binary notation with each digit in range with no leading zeros.

输入描述

    Input consists of a single line with two decimal integers  and 

输出描述

Output in decimal the number of representations the decimal number  has in redundant binary notation with each digit in range  with no leading zeros. Since the number of representations may be very large, output the answer modulo the large prime .

示例1

输入:

4 2

输出:

3

示例2

输入:

6 3

输出:

4

示例3

输入:

479 1

输出:

1

示例4

输入:

3846927384799 62

输出:

690163857

示例5

输入:

549755813887 2

输出:

1

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 19ms, 内存消耗: 672K, 提交时间: 2021-08-12 17:09:25

#include<iostream>
#include<map>
using namespace std;
map<long long, long long> arr;
long long n;
int t;
long long f(long long x) {
	long long ans = 0;
	long long st = 0;
	if (x > t) st = (x - t+1) / 2;
	long long sn = x / 2;
	for (long long i = st; i <= sn; i++) {
		if (!arr[i]) ans += f(i);
		else ans += arr[i];
		ans %= 998244353;
	}
	arr[x] = ans;
	return ans;
}
int main() {
	cin >> n >> t;
	arr[0] = 1;
	arr[1] = 1;
	long long ans = f(n);
	cout<<ans;
	return 0;
}

上一题