#P1214. Arithmetic Sequences in the Double Square Set
Arithmetic Sequences in the Double Square Set
Arithmetic Sequences in the Double Square Set
An arithmetic sequence can be represented in the form \(a, a+b, a+2b, \dots, a+(n-1)b\) where \(a\) is a non-negative integer and \(b\) is a positive integer.
In this problem, you are given two integers \(n\) and \(m\). Define the double square set as \[ S = \{ x \mid x = p^2 + q^2 \text{ with } p, q \in \mathbb{N} \cap [0, m] \}. \] Write a program to find all arithmetic sequences of length \(n\) such that every term of the sequence is an element of \(S\). Each sequence is denoted by its first term \(a\) and common difference \(b\). If there are multiple sequences, they should be output in increasing order of \(b\) and then \(a\). If no such sequence exists, print "NONE".
Note: You must use LaTeX formula formatting (within \( ... \) or \[ ... \]) when representing any formula.
inputFormat
The input consists of two lines:
- The first line contains an integer \(n\) (the length of the arithmetic sequence, \(n \ge 3\)).
- The second line contains an integer \(m\) (the upper bound for \(p\) and \(q\), with \(m \ge 1\)).
outputFormat
If one or more arithmetic sequences exist, output each sequence in a separate line in the format "a b
", where \(a\) is the first term and \(b\) is the common difference. Sequences must be ordered first by increasing \(b\) and then by increasing \(a\).
If no sequence exists, output a single line with the text "NONE".
sample
4
10
4 3
20 6