Code Permutations

Time limit2sMemory limit128 MB

Summary
Count permutations of 1..N whose order (LCM of cycle lengths) equals K, modulo 2^31-1.
Level

Hard8 of 10

Topics
Combinatorics, Dynamic programming, Number theory, Math
Solved
No attempts yet

Problem

You must break into a safe whose lock accepts the natural numbers from 11 to NN entered in one fixed secret order. That order is a permutation of 1,2,…,N1, 2, \dots, N, and you know for certain that this permutation has order exactly KK.

The order of a permutation is the smallest positive integer mm such that applying the permutation mm times returns every element to its original position. Equivalently, it is the least common multiple of the lengths of the permutation's cycles. For example, the code 2 3 12\ 3\ 1 has order 33, since 1→3→2→11 \to 3 \to 2 \to 1, 2→1→3→22 \to 1 \to 3 \to 2, and 3→2→1→33 \to 2 \to 1 \to 3.

Knowing the order narrows down how many codes you might have to try, and you want that count exactly. Because you refuse to acknowledge any number larger than the prime P=231−1P = 2^{31} - 1, report the count modulo PP (so a count of 2312^{31}, for instance, becomes 231 mod P=12^{31} \bmod P = 1).

Given NN and KK, determine how many permutations of {1,…,N}\{1, \dots, N\} have order exactly KK, modulo 231−12^{31} - 1.

Input

A single line with two integers NN and KK (1≤N≤1001 \le N \le 100, 1≤K≤231−11 \le K \le 2^{31} - 1).

Output

Print one integer: the number of permutations of NN elements whose order is exactly KK, taken modulo 231−12^{31} - 1.

Examples3

  1. Example 1

    Input
    3 2
    
    Expected output
    3
    
  2. Example 2

    Input
    6 6
    
    Expected output
    240
    
  3. Example 3

    Input
    15 12
    
    Expected output
    1789014075