Skip to main content
10 events
when toggle format what by license comment
Sep 18, 2014 at 15:50 history edited user2566092 CC BY-SA 3.0
added 31 characters in body
Sep 18, 2014 at 15:36 history edited user2566092 CC BY-SA 3.0
added 183 characters in body
Sep 18, 2014 at 15:35 comment added user2566092 @Olayinka See the bottom of my updated answer for a possible fix.
Sep 18, 2014 at 9:00 comment added Olayinka i understand, how do you suggest I fix this?
Sep 17, 2014 at 22:35 history edited user2566092 CC BY-SA 3.0
added 593 characters in body
Sep 17, 2014 at 22:31 comment added user2566092 @Olayinka Actually I did think of something. When your expression under the square root is a perfect square, it's possible because of round-off error that you will get a floating point number slightly less than the integer square root, so when you cast to an integer you will get 1 less than you should. Check to see if your incorrect answers are close but slightly smaller than the correct answer, and if so, that's likely what's going on. I'll update my answer to reflect this.
Sep 17, 2014 at 22:29 comment added user2566092 @Olayinka I'm not sure what's going on then. If the formula is correct, your function should work for all integers $\leq 10^9$ if long longs are 64 bit, so the only thing I can think is that you are running on an older machine where long longs are still 32 bit.
Sep 17, 2014 at 21:24 comment added Olayinka but the limit of r is $4\cdot 10^7$ which when squared can still fit into a signed long long
Sep 17, 2014 at 21:11 history edited user2566092 CC BY-SA 3.0
added 10 characters in body
Sep 17, 2014 at 21:05 history answered user2566092 CC BY-SA 3.0