#B3879. Sum of Consecutive Numbers Equal to a Perfect Square
Sum of Consecutive Numbers Equal to a Perfect Square
Sum of Consecutive Numbers Equal to a Perfect Square
Given two integers \(n\) and \(k\), count the number of sequences of \(k\) consecutive numbers within the range \(1\) to \(n\) whose sum is a perfect square. The sum of a sequence starting at an integer \(a\) can be expressed as:
\( S = k \cdot a + \frac{k(k-1)}{2} \)
A number \(S\) is a perfect square if there exists an integer \(x\) such that \(S = x^2\).
inputFormat
The input consists of two space-separated integers \(n\) and \(k\), where \(1 \leq k \leq n\) and \(n\) is a positive integer.
outputFormat
Output a single integer representing the count of contiguous sequences of \(k\) numbers from \(1\) to \(n\) whose sum is a perfect square.
sample
20 3
2