#484
Unrated
Exercise
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

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

As before, Farmer John's NN cows (1N75001\le N\le 7500) 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 AiA_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 and immediately return to the same order. If A=(2,3,1,5,4)A=(2,3,1,5,4), then the cows perform six steps before returning to the original order. 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)

Compute the product of the numbers of steps needed over all N!N! possible permutations AA of length NN.

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

Contestants using C++ may find the following code from KACTL helpful. Known as the Barrett reduction, it allows you to compute a%ba \% b several times faster than usual, where b>1b>1 is constant but not known at compile time. (we are not aware of such an optimization for Java, unfortunately).

#include <bits/stdc++.h> using namespace std;

typedef unsigned long long ull; typedef __uint128_t L; struct FastMod { ull b, m; FastMod(ull b) : b(b), m(ull((L(1) << 64) / b)) {} ull reduce(ull a) { ull q = (ull)((L(m) * a) >> 64); ull r = a - q * b; // can be proven that 0 <= r < 2*b return r >= b ? r - b : r; } }; FastMod F(2);

int main() { int M = 1000000007; F = FastMod(M); ull x = 10ULL*M+3; cout << x << " " << F.reduce(x) << "\n"; // 10000000073 3 }

입력

The first line contains NN and MM.

출력

A single integer.

예제 입력 1

5 1000000007

예제 출력 1

369329541

점수

Test case 2 satisfies N=8N=8.Test cases 3-5 satisfy N50N\le 50.Test cases 6-8 satisfy N500N\le 500.Test cases 9-12 satisfy N3000N\le 3000.Test cases 13-16 satisfy no additional constraints.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.