Exercise

N과 소수 M이 주어질 때, 길이 N인 순열의 위수가 정확히 K가 되는 모든 양의 정수 K의 합을 M으로 나눈 나머지를 구한다.

어려움8정수론조합론동적 계획법수학아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Farmer John has come up with a new morning exercise routine for the cows (again)!

As before, Farmer John's NN cows (1N1041\le N\le 10^4) are standing in a line. The ii-th cow from the left has label ii for each 1iN1\le i\le N. He tells them to repeat the following step until the cows are in the same order as when they started.

  • Given a permutation AA of length NN, the cows change their order such that the ii-th cow from the left before the change is A_iA\_i-th from the left after the change.

For example, if A=(1,2,3,4,5)A=(1,2,3,4,5) then the cows perform one step. If A=(2,3,1,5,4)A=(2,3,1,5,4), then the cows perform six steps. The order of the cows from left to right after each step is as follows:

  • 0 steps: (1,2,3,4,5)(1,2,3,4,5)
  • 1 step: (3,1,2,5,4)(3,1,2,5,4)
  • 2 steps: (2,3,1,4,5)(2,3,1,4,5)
  • 3 steps: (1,2,3,5,4)(1,2,3,5,4)
  • 4 steps: (3,1,2,4,5)(3,1,2,4,5)
  • 5 steps: (2,3,1,5,4)(2,3,1,5,4)
  • 6 steps: (1,2,3,4,5)(1,2,3,4,5)

Find the sum of all positive integers KK such that there exists a permutation of length NN that requires the cows to take exactly KK steps.

As this number may be very large, output the answer modulo MM (108M109+710^8\le M\le 10^9+7, MM is prime).

입력

The first line contains NN and MM.

출력

A single integer.

힌트

There exist permutations that cause the cows to take 11, 22, 33, 44, 55, and 66 steps. Thus, the answer is 1+2+3+4+5+6=211+2+3+4+5+6=21.