#P11496. Minimum Perfect Square in a Modified Sequence
Minimum Perfect Square in a Modified Sequence
Minimum Perfect Square in a Modified Sequence
Consider the sequence defined by starting with an integer \( k \) and then adding consecutive odd numbers:
\( a_0 = k,\quad a_i = k + \sum_{j=1}^{i} (2j-1) = k + i^2,\quad i \ge 0. \)
Your task is to find the smallest term in this sequence which is a perfect square, and output its square root. Note that 0 is considered a perfect square.
inputFormat
The input consists of a single integer \( k \). You may assume that there exists an index \( i \ge 0 \) such that \( k+i^2 \) is a perfect square.
outputFormat
Output the non-negative integer \( m \) such that \( m^2 \) is the smallest perfect square found in the sequence.
sample
0
0