CCO Preparation Test 3 P1 - Primitive Pythagorean Pairs

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 0.6s
Memory limit: 128M

Author:
Problem type

Do you know the Pythagorean theorem? Definitely yes. Do you know Pythagorean triples? Maybe not. Do you know primitive Pythagorean pairs? Definitely not, because Bruce has not defined it yet! Let's start from Pythagorean triples. A Pythagorean triple consists of three positive integers a, b, and c, such that a^2 + b^2 = c^2. If a and b are also coprime, the pair (a, b) is named a primitive Pythagorean pair, like (3, 4). Bruce will tell you how to generate primitive Pythagorean pairs. Given two positive integers m and n (m>n), if m and n are coprime and m-n is odd, a primitive Pythagorean pair (a, b) can be calculated by a = m^2-n^2 and b = 2 \times m \times n. There are an infinite number of primitive Pythagorean pairs.

Now Bruce has N cards, each of which has a positive integer v_i (1 \le i \le N). He wants to pick up a number of cards so that there are no primitive Pythagorean pairs among the selected cards. Could you please help Bruce to get the total number of different selections? Two selections are different if and only if one card is in one selection, but is not in the other selection. Bruce has to select at least one card in each selection.

Constraints

For all subtasks:

1 \le N \le 1\,000\,000

Subtask 1 [30%]

1 \le v_i \le 3\,000

Subtask 2 [30%]

1 \le v_i \le 200\,000

Subtask 3 [40%]

20\,000 \le v_i \le 1\,000\,000

Input Specification

The first line of input will consist of one integer, N, the number of cards Bruce has.

The second line of input will consist of N positive integers v_1, v_2, \dots, v_N, where v_i is the value of card i (1 \le i \le N).

Output Specification

Output one integer, the number of different selections modulo 10^9+7.

Sample Input

4
5 12 35 5

Sample Output

8

Explanation of Output for Sample Input

There are two primitive Pythagorean pairs (5, 12) and (12, 35). So, there are 8 different selections: \{5\}, \{12\}, \{35\}, \{5\}, \{5, 35\}, \{35, 5\}, \{5, 5\}, \{5, 35, 5\}.


Comments

There are no comments at the moment.