Bitwise OR Sequences

0

0 votes
Dynamic Programming, Algorithms, Approved, Hard
Problem

For some number X, let F(X) denote the total number of sequences having length ≤ K such that bitwise OR of all the elements in a sequence is equal to X.

For a given N , K and prime p, calculate the value of Ni=0 pi * F(i).

Input:
Input will consists of several test cases.
First line of input will consists of a single integer T denoting the number of test cases. Each of the next T lines consist of integers N , K and p separated by a single space.

Output:
For each test case, output Ni=0 pi * F(i). Since, the value can be large, output the value modulo 109+7.

Constraints:

  • 1T104
  • 0N<232
  • 1K106
  • 2p<106 where p is a prime number.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For first test case, F(0) = 2, F(1) = 4, F(2)=4, F(3) = 10.
For second test case, F(0) = 3, F(1)= 11, F(2)= 11, F(3)= 59, F(4)= 11, F(5)= 59.

Editor Image

?