Under construction

Still being built. Things may change

Beautiful Permutations

Interview

Time limit1sMemory limit1024 MB

Summary
Given n and k, count the permutations of 1 to n whose sum of adjacent products is divisible by k.
Level

Medium5 of 10

Topics
Dynamic programming, Bit manipulation, Brute force
Solved
No attempts yet

Statement

A permutation of size nn is an array ⟨a1,a2,…,an⟩\langle a_1, a_2, \ldots, a_n \rangle of distinct integers from 11 to nn. Each number appears in the permutation exactly once.

Senya calls the beauty of a permutation ⟨a1,a2,…,an⟩\langle a_1, a_2, \ldots, a_n \rangle the value a1a2+a2a3+…+an−1ana_1a_2 + a_2a_3 + \ldots + a_{n-1}a_n. He wants to count the permutations whose beauty is divisible by kk.

Given nn and kk, find the number of permutations of size nn whose beauty is divisible by kk.

Input

Two integers nn and kk are given (1≤n≤101 \le n \le 10, 2≤k≤10002 \le k \le 1000).

Output

Print one integer: the number of permutations of size nn whose beauty is divisible by kk.

Examples1

  1. Example 1

    Input
    3 2
    
    Expected output
    2