PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000232. Đếm cặp có tích là số chính phương (Square Pair)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm cặp có tích là số chính phương (Square Pair)
Đếm cặp có tích là số chính phương (Square Pair)
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given nonnegative integers, count pairs for which the product is a perfect square. Zero is a perfect square.
Input
- First line: integer .
- Second line: array elements.
Output
Print the number of qualifying pairs.
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): .
Examples
Example 1
Input
5
0 3 2 8 12
Output
6
Explanation
Four valid pairs contain zero, and the other two satisfy and .
Example 2
Input
8
2 2 4 6 3 100 100 25
Output
7
Explanation
Pairs with equal squarefree kernels, taking zero into account, contribute the answer.