ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1153. Supercomputer

be carefull ...
Posted by arrammis 9 Jul 2015 18:13
If you use newton's method to find a square root make sure that your division algorithm for 2 big integers is fast enough to handle quickly a lot of divisions that requires newtons method, otherwise you will get TL ... even with O(n*log(BASE)) time complexity division algorithm your going to get TL.
Faster division at O(n) is described in Knuth's The Art of Computer Sience 2 edition, page 298 or 299...

So in case if yo get TL with newton's method (which has got actually better time complexity than binary search root finding) just use binary search algo for root with BASE = 10^9 for you big integers, it needs only division by 2, *, +, and - operations needed for big integer.
If input contains 600 digits you will only need 600 / 9 array elements to store that number ... and with less divisions you will get AC!

take care ...

Edited by author 09.07.2015 18:17