Under construction

Still being built. Things may change

Tikal

Time limit2sMemory limit1024 MB

Summary
Count the distinct ways to place k identical figurines on the n sides of a regular n-gon, treating rotations as the same, modulo prime p.
Level

Medium6 of 10

Topics
Combinatorics, Number theory
Solved
No attempts yet

Problem

The Maya built a beautiful temple in the city of Tikal. The temple is a regular nn-gon whose sides are indistinguishable. By tradition, kk identical idol figurines were placed inside the temple. The shamans insist that the figurines must stand by the walls of the temple, meaning the sides of the nn-gon. Different walls may hold different numbers of figurines. Following custom, the Chief Shaman must rearrange the figurines into a new configuration every morning.

After the temple was built, spirits appeared and warned that once a configuration of figurines repeats, the sky will fall, the seas will overflow, and the world will end. They also clarified that configurations obtained by rotating the temple are considered the same.

The Chief Shaman asks how many distinct configurations of the figurines exist in the temple. Since this number can be very large, he wants the answer modulo the prime pp.

Input

The first line contains three integers nn, kk, and pp (3≤n≤500 0003 \le n \le 500\,000; 1≤k≤500 0001 \le k \le 500\,000; 106<p<10910^6 < p < 10^9). It is guaranteed that pp is prime.

Output

Print a single integer: the number of distinct arrangements of kk idols among the nn walls of the temple, counting configurations equal under rotation as one, modulo pp.

Hint

In the second test case, the possible arrangements are:

(33,00,00,00,00,00) (22,11,00,00,00,00) (22,00,11,00,00,00) (22,00,00,11,00,00) (22,00,00,00,11,00)

(22,00,00,00,00,11) (11,11,11,00,00,00) (11,11,00,11,00,00) (11,11,00,00,11,00) (11,00,11,00,11,00)

Examples2

  1. Example 1

    Input
    4 1 1000003
    
    Expected output
    1
    
  2. Example 2

    Input
    6 3 1000003
    
    Expected output
    10