#CT0000064. Số chính phương gần nhất - EP1 (Nearest Perfect Square - EP1)
Số chính phương gần nhất - EP1 (Nearest Perfect Square - EP1)
Nearest Perfect Square - EP1
Version: Phuoc Hung OJ Extended
Problem Statement
A positive integer is called a perfect square if it is the square of a positive integer. For example, are perfect squares.
You are given a positive integer . For each perfect square , define its distance to as .
Find the perfect square with minimum distance to , and also output the minimum distance .
Input
One line containing the positive integer .
Output
Print two integers and , where is the perfect square closest to and .
Subtasks
- Subtask 1 (30 points): .
- Subtask 2 (30 points): .
- Subtask 3 (40 points): .
Examples
Example 1
Input
20
Output
16 4
Explanation
The two perfect squares around 20 are and . Their distances are 4 and 5, so the answer is 16 with distance 4.
Example 2
Input
24
Output
25 1
Explanation
and , so the answer is 25 1.
Example 3
Input
30
Output
25 5
Explanation
The adjacent perfect squares are and . Their distances are 5 and 6, so 25 is closer.
Example 4
Input
81
Output
81 0
Explanation
is already a perfect square, so the minimum distance is 0.
Example 5
Input
999999999999999999
Output
1000000000000000000 1
Explanation
is exactly one greater than , so it is the closest perfect square.