CHNGFUNC - Editorial

I used two pointer technique. First I stored all the squares till the maximum possible perfect square one can get in a vector. Then I used the difference of values of two pointer to check the condition |x^2-y^2|<=b.
My solution : CodeChef: Practical coding for everyone

Really neat solution!! My (tester’s) solution is based on the fact that the bound on answer won’t be large.

Yup, this approach is really neat. I think its like, less than 10 lines of code (ignoring headers and stuff)

write y=(n2−1)x2y=(n2−1)x2 where n>=2n>=2.

Does this not imply that y HAS to be a integral multiple of x? And its not the case, say for x=2 and y=5. y cannot be expressed as y= (n*n-1)*x [where n is integer] but it forms a square.

It looks like your approach misses out some cases. What do you think?

Anyone, please help!! I couldn’t find what’s wrong with my solution.

@vijju123 Yeah!! I got it. My solution was only considering the integral value of n but the fractional value of n does also contribute to the answer.
for example your case of x=2 and y=5, n=1.5 does also contribute to the answer.
Thank you for the test case!!

\sum_{i=1}^{n}\frac{1}{i}=O(log(n))

can you tell me the complexity of your solution?