Problem · Dynamic Programming

Count Integer Sequences

Learn this problem
HardXperiINTERNOA

Problem statement

Print the number of integer sequences of length N, A = {A1, A2, A3...., AN} possible where the Sequence A should follow the conditions below:

  1. All elements in A should be between 0 and M (inclusive)
  2. XOR of all the elements in A is equal to X

Print the number of integer sequence satisfying these conditions modulo 998244353.

Input Format:

N, M , X

Function

countIntegerSequences(N: long, M: long, X: long) → int

Complete the function countIntegerSequences in the editor.

countIntegerSequences has the following parameters:

  1. N: the length of the sequence
  2. M: the maximum value of the elements in the sequence
  3. X: the XOR value to be achieved

Returns

int: the number of integer sequences modulo 998244353

Examples

Example 1

N = 200M = 9000606388LX = 317329110return = 788002104
The output is the number of integer sequences of length N that satisfy the given conditions modulo 998244353.

Example 2

N = 3M = 3X = 2return = 5
The 5 sequences of length N(3) that satisfy both the conditions are: (0, 0, 2), (0, 1, 3), (1, 1 ,2), (2, 2, 2), (2, 3, 3). All the sequences are of length N(3), all the elements in the sequence are between 0 and M(3) inclusive and xor of all the elements in the individual sequence is equal to X(2).

More Xperi problems

drafts saved locally
public int countIntegerSequences(long N, long M, long X) {
  // write your code here
}
N200
M9000606388L
X317329110
expected788002104
checking account