GlobeX Cup '18 S3 - Playing With Bits

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types

August is doing his binary math homework. While doing it, he came up with a problem, and thought it would be a good problem to put on the GlobeX Canada Cup.

August gives you 3 questions. Given the integers N, M, K, and V, how many ways are there to make an integer array a of length N where 0ai<2K such that:

  1. a1a2a3aN=V?
  2. a1a2a3aN=V?
  3. a1&a2&a3&&aN=V?

Note that:

  • denotes the bitwise xor operation (^ in most languages).
  • denotes the bitwise or operation (| in most languages).
  • & denotes the bitwise and operation (& in most languages).

Since August has meganumerophobia, he wants the answer to each question modulo M.

Input Specification

The first line and only line will contain 4 space-separated integers N,M,K,V (1N109,1M2×109,0K63,0V<2K).

Output Specification

On the first line, output the answer to question 1, modulo M.
On the second line, output the answer to question 2, modulo M.
On the last line, output the answer to question 3, modulo M.

Subtasks

Subtask 1 [5%]

N8,K3

Subtask 2 [15%]

N103,M=109+7

Subtask 3 [60%]

N105

Subtask 4 [20%]

No additional constraints.

Sample Input 1

Copy
2 1000000007 3 5

Sample Output 1

Copy
8
9
3

Sample Input 2

Copy
8 1000000007 1 0

Sample Output 2

Copy
128
1
255

Comments

There are no comments at the moment.