среда, 16 апреля 2014 г., 13:56:05 UTC-5 пользователь Sumit Tiwari написал:
> hey for the input
> 1 1000000000000000000
> 
> my ans is : 707106781 but original o/t is 707106780
> 
> and for 10000000000000000 1000000000000000000
> it is : 51 here is 49
> 
> i have taken long as data type.

a) most likely you have problem with float overflow - even if you do all 
arithmetic in integer numbers, when you take square root it gets converted into 
float and truncated.

b) if you insist on doing solution the way you do - I call it "closed form" 
solution, when you derive formula and plug numbers in - then you need integer 
root function. You can dig it up on the internet somewhere.

c) better option - especially when you are in competition - whenever you have 
monotonically increasing function - and this is good example of it - use binary 
search. In this case you would need to do calculation only one way - forward, 
no integer roots. In terms of speed it is a little bit slower, but it doesn't 
matter for such fast problem.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/ad40cd91-f2f0-403e-93bd-aacc15155c42%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to