Easy Array Counting#12254

Easy Array Counting (Editorial)

Problem Author:

Hasan Saleh (MathModel)

Prepared by:

Hasan Saleh (MathModel)

Edited by:

Hasan Saleh (MathModel)

Solution

For the only choice is (a=b) and this case the answer is 1 anyways.

For other we've the following array assuming common difference :

[a,a+d,a+2d,...,a+(n-1)d]

now we want to determine that's a+(n-1)d \le b this gives us

b-a = (n-1)d \implies \max(d)=\left \lfloor \frac{b-a}{n-1} \right \rfloor

and all d \in \{0,1,...,\left \lfloor \frac{b-a}{n-1} \right \rfloor\} will work thus the answer is \left \lfloor \frac{b-a}{n-1} \right \rfloor+1.

Complexity .

for _ in range(int(input())):
    n,a,b=map(int,input().split())
    if(n==1):
        print(1)
        continue
    print((b-a)//(n-1)+1)