You are viewing a single comment's thread. Return to all comments →
Please explain:-
int numSquares = (int) (Math.floor(Math.sqrt(B)) - Math.ceil(Math.sqrt(A)) + 1);
Lets say we have to calculate from 26 to 70.
Math.floor(Math.sqrt(B)) would give 8.
Math.ceil(Math.sqrt(A)+1)would give 7
So int numSquares would be=8-7 which is equal to 1. Which will be wrong.
It should be "[36,49,64]" totalling to 3.
Sherlock and Squares
You are viewing a single comment's thread. Return to all comments →
Please explain:-
int numSquares = (int) (Math.floor(Math.sqrt(B)) - Math.ceil(Math.sqrt(A)) + 1);
Lets say we have to calculate from 26 to 70.
Math.floor(Math.sqrt(B)) would give 8.
Math.ceil(Math.sqrt(A)+1)would give 7
So int numSquares would be=8-7 which is equal to 1. Which will be wrong.
It should be "[36,49,64]" totalling to 3.