#B3878. Count Perfect Square Sums in Consecutive Numbers
Count Perfect Square Sums in Consecutive Numbers
Count Perfect Square Sums in Consecutive Numbers
Given two integers (n) and (k), determine the number of sequences of (k) consecutive numbers taken from (1) to (n) whose sum is a perfect square.
For a starting index (i) (where (1 \le i \le n-k+1)), the sum of the consecutive sequence is given by:
[
S = k \cdot i + \frac{k(k-1)}{2}
]
A sum (S) is a perfect square if there exists an integer (m) such that (S = m^2).
inputFormat
Input consists of a single line containing two space-separated integers: (n) and (k).
outputFormat
Output a single integer representing the count of (k)-length consecutive segments from (1) to (n) whose sum is a perfect square.
sample
10 2
1