Under construction

Still being built. Things may change

Subspace

Time limit1sMemory limit512 MB

Summary
Count the k-dimensional subspaces of the n-dimensional vector space over F_q, printing the answer modulo a prime p.
Level

Medium7 of 10

Topics
Combinatorics, Number theory, Math
Solved
No attempts yet

Problem

bobo is a big fan of linear algebra! He plans to count the number of kk-dimension subspaces in Fqn\mathbb{F}_q^n modulo pp.

For those who are not familiar with linear algebra:

  • Fq\mathbb{F}_q is the set {0,1,…,q−1}\{0, 1, \dots, q - 1\}, with addition and multiplication modulo qq defined on;
  • Fqn\mathbb{F}_q^n is the nn-dimension vector space {(x1,x2,…,xn):x1,x2,…,xn∈Fq}\{(x_1, x_2, \dots, x_n) : x_1, x_2, \dots, x_n \in \mathbb{F}_q\};
  • A subset K⊆FqnK \subseteq \mathbb{F}_q^n is a subspace, if and only if for all p,q∈K\mathbf{p}, \mathbf{q} \in K, p+q∈K\mathbf{p} + \mathbf{q} \in K;
  • The dimension of subspace KK is the cardinality of the maximal independent subset;
  • A subset {p1,p2,…,pk}⊆K\{\mathbf{p}_1, \mathbf{p}_2, \dots, \mathbf{p}_k\} \subseteq K is called independent if and only if the equation c1⋅p1+c2⋅p2+⋯+ck⋅pk=0c_1 \cdot \mathbf{p}_1 + c_2 \cdot \mathbf{p}_2 + \dots + c_k \cdot \mathbf{p}_k = 0 has only the solution c1=c2=⋯=ck=0c_1 = c_2 = \dots = c_k = 0.

Input

Four integers q,n,k,pq, n, k, p are given (2≤q≤1092 \leq q \leq 10^9, 1≤k≤n≤1091 \leq k \leq n \leq 10^9, 2≤p≤2⋅1052 \leq p \leq 2 \cdot 10^5). It is guaranteed that pp and qq are prime numbers.

Output

Print a single integer, the number of subspaces.

Examples1

  1. Example 1

    Input
    2 3 2 100003
    
    Expected output
    7