#K50692. Nearest Perfect Square

    ID: 28921 Type: Default 1000ms 256MiB

Nearest Perfect Square

Nearest Perfect Square

Given an integer n, compute the largest perfect square that is less than or equal to n. A perfect square is defined as a number that can be expressed as \(m^2\), where \(m\) is a non-negative integer. If \(n < 1\), then the answer is 0.

More formally, for an integer \(n\), find the integer \(m\) such that \(m^2 \leq n < (m+1)^2\), and output \(m^2\). For instance, when \(n=10\), the nearest perfect square is 9; when \(n=15\), it is 9; when \(n=1\), it is 1; and when \(n\) is 0 or negative, the output should be 0. The solution must handle all these cases appropriately.

The program should read input from standard input (stdin) and write the result to standard output (stdout).

inputFormat

The input consists of a single line containing one integer (n).

outputFormat

Output a single integer representing the largest perfect square less than or equal to (n). If (n < 1), output 0.## sample

10
9