#SP0000233. Ba chiếc ghế (Three Chairs)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Ba chiếc ghế (Three Chairs)
Three Chairs
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Kira has friends. Friend has height , and all heights are distinct. Kira has only three chairs, so he wants to invite a group of exactly three different friends.
A group is valid if the smallest and largest heights in that group are coprime, that is, their greatest common divisor is . There is no additional restriction on the middle height.
Count the valid groups of exactly three friends. Groups are different if their sets of friends differ; seating order does not count.
Input
Line 1 contains . Line 2 contains exactly pairwise distinct integers .
Output
Print one integer: the number of valid groups of three friends.
Subtasks
-
Subtask 1 (20 points): ; for all ; all distinct.
-
Subtask 2 (30 points): ; for all ; all distinct.
-
Subtask 3 (50 points): ; for all ; all distinct.
Examples
Input
4
1 6 2 3
Output
3
Explanation
The heights sorted are . The four triples are , , , and . Their extreme-height gcds are , respectively. Exactly three triples are valid, so print .