PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#DSU0000047. Số học môđun kỳ lạ (Moodular Arithmetic)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số học môđun kỳ lạ (Moodular Arithmetic)
Moodular Arithmetic
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an odd prime and an integer satisfying . Consider the residue set .
Count the functions such that the following equality holds for every :
A function is determined by all values . Two functions are different if their outputs differ for at least one argument. The function is not required to be injective, surjective, or a permutation. Because the count may be very large, output it modulo .
Input
A single line contains ; is an odd prime.
Output
Print the number of valid functions modulo .
Subtasks
- Subtask 1 (20 points): ; is an odd prime; .
- Subtask 2 (30 points): ; is an odd prime; .
- Subtask 3 (50 points): ; is an odd prime; .
Examples
Input
5 4
Output
25
Explanation
There are two independent cycles among the nonzero residues; each provides five choices.