Bug #21217
closedInteger.sqrt produces wrong results even on input <= 1e18
Description
Hello, I have been so far using Ruby in various online judge platforms that support it, while recently I discovered a very intriguing issue regarding Integer.sqrt
.
Please refer to the two following verdicts on this recent problem that requires the usage of such a function:
The input constraints of the problem guarantees that n <= 1e18, and judging from the fact that implementing the same functionality using binary search gets a correct verdict, it is quite apparent that Integer.sqrt
is producing wrong results even on input <= 1e18.
While I have not been able to reproduce this issue locally, it is not hard to imagine that the latest version of Ruby might still have the same issue considering there has been no similar bugfix request in the last 2~3 years.
I believe an easy way to fix this bug is to simply adjust the result to the correct one using a linear search (while(x*x<=n)x++; while(x*x>n)x--;
) in the end.
Thank you for reading the bugfix request, and for your continued effort on maintaining the language.