Problem:
Score : 200 points

Problem Statement

Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

Constraints

1 \leq N \leq 10^9

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the largest square number not exceeding N.

Sample Input 1

10

Sample Output 1

9

10 is not square, but 9 = 3 × 3 is. Thus, we print 9.

Sample Input 2

81

Sample Output 2

81

Sample Input 3

271828182

Sample Output 3

271821169

Solution in Scala (2.11.7) (judge verdict: Accepted)

import scala.annotation.tailrec

object Main extends App {
  val n = io.StdIn.readInt()

  @tailrec
  def searchRec(i: Int): Int = {
    if (i == 0) 0
    else {
      val sqrt = math.sqrt(i)
      if (sqrt - sqrt.toInt == 0) i else searchRec(i - 1)
    }
  }

  println(searchRec(n))
}