#P3213. [HNOI2011] 勾股定理

    ID: 2262 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2011湖南枚举,暴力连通块最大公约数,gcd

[HNOI2011] 勾股定理

Description

Momo has been studying the Pythagorean Theorem. For two positive integers AA and BB, if there exists a positive integer CC such that A2+B2=C2A^2 + B^2 = C^2, and AA and BB are coprime, then (A,B)(A, B) is called a primitive Pythagorean pair.

One day, Momo obtained NN sticks, each with a positive integer length. She plans to select some of these sticks to play a puzzle game. To make the pattern look artfully messy, she wants the lengths of any two selected sticks to not form a primitive Pythagorean pair. Now, Momo wants to know how many selection schemes meet the requirement. Since the answer may be large, you only need to output the result modulo 109+710^9 + 7.

Input Format

The first line contains a positive integer NN, the number of sticks.

The second line contains NN space-separated positive integers h1,h2,,hNh_1, h_2, \cdots, h_N, where for 1iN1 \le i \le N, hih_i denotes the length of the ii-th stick.

The testdata guarantees that:

  • For 30%30\% of the testdata, for all 1iN1 \le i \le N, 1hi30001 \le h_i \le 3000.
  • For another 30%30\% of the testdata, for all 1iN1 \le i \le N, 1hi2×1051 \le h_i \le 2 \times 10^5.
  • For the remaining 40%40\% of the testdata, for all 1iN1 \le i \le N, 2×104hi1062 \times 10^4 \le h_i \le 10^6.
  • For 100%100\% of the testdata, N106N \le 10^6.

Output Format

Output a single non-negative integer, the number of valid selection schemes modulo 109+710^9 + 7.

4				
5 12 35 5	

8

Hint

Sample explanation: (5,12)(5, 12) and (12,35)(12, 35) are primitive Pythagorean pairs, so there are 88 valid selection schemes, namely:

$\{5\}, \{12\}, \{35\}, \{5\}, \{5,35\}, \{35,5\}, \{5,5\}, \{5,35,5\}$.

Translated by ChatGPT 5