#P5172. Summation of Alternating Series with Floor Function

    ID: 18410 Type: Default 1000ms 256MiB

Summation of Alternating Series with Floor Function

Summation of Alternating Series with Floor Function

Given two positive integers n and r, compute the summation:

$$\sum_{d=1}^{n}(-1)^{\lfloor d\sqrt{r} \rfloor}$$

where \(\lfloor x \rfloor\) denotes the floor function. The task is to calculate the sum of \((-1)^{\lfloor d\sqrt{r} \rfloor}\) for all \(d\) from 1 to \(n\). ## inputFormat The input consists of a single line containing two positive integers n and r separated by a space. ## outputFormat Output a single integer, the result of the summation $$\sum_{d=1}^{n}(-1)^{\lfloor d\sqrt{r} \rfloor}.$$

sample

1 1
-1