#C12890. Extract Perfect Squares
Extract Perfect Squares
Extract Perfect Squares
You are given a list of integers. Your task is to extract all the perfect squares from the list and print each perfect square along with its integer square root. A number \(x\) is said to be a perfect square if there exists an integer \(k\) such that \(x=k^2\) (with \(x \ge 0\)).
Example: If the input list is [1, 2, 3, 4, 5, 9, 16, 17]
, then the perfect squares are 1, 4, 9, and 16. Their respective square roots are 1, 2, 3, and 4, so the output should be:
1 1 4 2 9 3 16 4
Please note that the output must be sorted in ascending order of the perfect square numbers.
inputFormat
The first line contains a single integer \(n\) representing the number of elements. The second line contains \(n\) space-separated integers.
outputFormat
For each perfect square in the list, print a line containing two integers: the perfect square and its integer square root. The output should be in ascending order based on the perfect square value. If there are no perfect squares, print nothing.
## sample8
1 2 3 4 5 9 16 17
1 1
4 2
9 3
16 4
</p>