#GL0000363. Bài tập của đàn bò (Exercise)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài tập của đàn bò (Exercise)
Exercise
Source: USACO
Version: Phuoc Hung OJ Extended
Problem Statement
There are cows, labeled through . Consider a permutation of these labels. Apply the same permutation simultaneously to all positions, repeatedly, until the original order is restored.
The least positive number of applications is the order of the permutation. If its disjoint cycle lengths are , the order is .
Consider the set of distinct attainable permutation orders for permutations of elements. Compute the sum of those distinct positive integers modulo the prime . Different permutations with the same order contribute only once.
Input
One line with integers . is prime.
Output
A single integer, the sum modulo . The PHOJ version uses standard input/output instead of USACO's exercise.in and exercise.out files.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
5 1000000007
Output
21
Explanation
For N=5 the distinct possible return periods are 1,2,3,4,5,6. Their sum is 21.
Example 2
Input
1 998244353
Output
1
Explanation
A permutation of one element only contains a fixed point, so its order is 1.