#P10063. [SNOI2024] 平方数
[SNOI2024] 平方数
Background
The original time limit was 1.5 s.
Because it was hard to pass due to hack testdata, it was changed to 10 s.
Problem Description
You are given a sequence of positive integers . How many subarrays have a product that is a perfect square. In other words, how many pairs () satisfy that is a perfect square.
Input Format
The first line contains an integer , the number of integers.
The next line contains integers, .
Output Format
Output one integer, the number of subarrays whose product is a perfect square.
Then output these subarrays in lexicographical order, i.e., output by increasing .
If multiple subarrays have the same , output them by increasing . If the number of subarrays exceeds , output only the first .
10
1 2 3 4 6 8 9 12 16 18
12
1 1
1 5
2 5
3 6
3 7
4 4
4 8
4 9
5 8
5 9
7 7
9 9
3
999999999999999956000000000000000363 999999999999999844000000000000004059 999999999999999866000000000000001353
1
1 3
Hint
[Explanation for Sample #2]
In the second sample, the three numbers are , and every pairwise product is computed.
[Sample #3]
See the attachments square/square3.in and square/square3.ans.
This sample satisfies the constraint limits of test points .
[Sample #4]
See the attachments square/square4.in and square/square4.ans.
This sample satisfies the constraint limits of test points .
[Sample #5]
See the attachments square/square5.in and square/square5.ans.
This sample satisfies the constraint limits of test points .
[Constraints]
For all testdata, it is guaranteed that , .
Specifically:
| Test Point ID | ||
|---|---|---|
Translated by ChatGPT 5