PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000242. Tìm mô-đun tạo phần dư chiếm đa số (Yet Another mod M)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm mô-đun tạo phần dư chiếm đa số (Yet Another mod M)
Tìm mô-đun tạo phần dư chiếm đa số (Yet Another mod M)
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given pairwise distinct positive integers, find any modulus with such that strictly more than half of the elements share the same residue modulo . Output any valid , or -1 if none exists.
Input
- First line: integer .
- Second line: array elements. All elements must be distinct.
Output
Print any valid modulus , or -1 if no solution exists.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
5
3 17 8 14 10
Output
7
Explanation
Modulo 7 yields residues ; residue 3 appears three times out of five.
Example 2
Input
10
1 2 3 4 5 6 7 8 9 10
Output
-1
Explanation
No residue can appear more than five times under any modulus at least 3.