#GL0000376. Bộ bốn GCD bằng LCM (GCD <-> LCM)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bộ bốn GCD bằng LCM (GCD <-> LCM)
GCD <-> LCM
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of positive integers , an ordered quadruple is valid if:
- All four indices lie in and are pairwise distinct.
- .
Different index orders count separately: and represent two different quadruples. Equal values are permitted, but positions must never be reused within a quadruple.
Count all valid quadruples modulo .
PHOJ file convention: The original problem contains multiple test cases per execution. This edition places exactly one instance per .in file and removes the initial line; the online judge manages test files separately.
Input
The first line contains . The second line contains integers .
Output
Print the number of valid ordered quadruples modulo .
Subtasks
-
Subtask 1 (20 points): , .
-
Subtask 2 (30 points): , .
-
Subtask 3 (50 points): , .
Examples
Example 1
Input
4
4 3 1 1
Output
4
Explanation
Only the pair of values has GCD while the other two positions have LCM . Each ordered pair has two orientations, giving .
Example 2
Input
6
2 2 2 2 3 5
Output
24
Explanation
The four occurrences of value can be placed in the four ordered positions in ways. The values produce no additional valid quadruples.