NC225351. Redundant Binary Notation
描述
输入描述
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; }