Key Generation
Time limit1sMemory limit512 MB
Count the nonnegative integers up to N whose binary form has exactly K ones, given N as a hex string of up to 250 digits, modulo 998244353.
- Level
Medium7 of 10
- Topics
- Combinatorics, Dynamic programming, Bit manipulation, Math
- Solved
- No attempts yet
Problem
In the cryptographic system <>, a key can be any nonnegative integer whose binary representation contains exactly ones and which does not exceed a given positive integer .
Given and , compute how many distinct keys exist. Since the answer can be very large, output its remainder modulo the prime .
Input
The first line contains a single integer written in hexadecimal notation without leading zeros (). Digits greater than 9 are denoted by uppercase Latin letters from 'A' to 'F'.
The second line contains a single integer , the number of bits in the key that equal one ().
Output
Print a single number: the remainder when the number of distinct keys that exist for the given and is divided by the prime .