N과 소수 M이 주어질 때, 길이 N인 순열의 위수가 정확히 K가 되는 모든 양의 정수 K의 합을 M으로 나눈 나머지를 구한다.
어려움8정수론조합론동적 계획법수학아직 제출이 없습니다시간 제한1초메모리 제한512 MBFarmer John has come up with a new morning exercise routine for the cows (again)!
As before, Farmer John's N cows (1≤N≤104) are standing in a line. The i-th cow from the left has label i for each 1≤i≤N. He tells them to repeat the following step until the cows are in the same order as when they started.
For example, if A=(1,2,3,4,5) then the cows perform one step. If 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:
Find the sum of all positive integers K such that there exists a permutation of length N that requires the cows to take exactly K steps.
As this number may be very large, output the answer modulo M (108≤M≤109+7, M is prime).
The first line contains N and M.
A single integer.
There exist permutations that cause the cows to take 1, 2, 3, 4, 5, and 6 steps. Thus, the answer is 1+2+3+4+5+6=21.