This page is still under construction.

Parts of this page are still being built. What you see may change.

Binomial Coefficient 5

Time limit1sMemory limit256 MB

Summary
Compute the remainder of the binomial coefficient C(N, K) divided by M, where M is not necessarily prime.
Level

Medium7 of 10

Topics
Number theory, Combinatorics
Solved
No attempts yet

Problem

You are given a natural number NN and an integer KK. Write a program that computes the remainder of the binomial coefficient (NK)\binom{N}{K} divided by MM. MM is not guaranteed to be prime.

Input

The first line contains NN, KK, and MM, separated by spaces. (1≤N≤4×1061 \le N \le 4 \times 10^6, 0≤K≤N0 \le K \le N, 2≤M≤4×1062 \le M \le 4 \times 10^6)

Output

Print the remainder of (NK)\binom{N}{K} divided by MM on the first line.

Examples5

  1. Example 1

    Input
    5 2 3
    
    Expected output
    1
    
  2. Example 2

    Input
    30 3 3
    
    Expected output
    1
    
  3. Example 3

    Input
    100 45 13
    
    Expected output
    2
    
  4. Example 4

    Input
    100 46 72
    
    Expected output
    48
    
  5. Example 5

    Input
    50 23 9
    
    Expected output
    1