1 / 5
Jun 2008

This looked like a pretty straightforward problem, but my code keeps geeting TLE. I tried using psyco and making an iterative instead of recursive solution.

Can those who have already solved this offer any insight?

Thanks in advance.

  • created

    Jun '08
  • last reply

    Jul '08
  • 4

    replies

  • 121

    views

  • 3

    users

Make sure you're not attempting to actually convert the numbers to ints. Python can handle 30000-bit integers, but not nearly fast enough for this problem.

Avoid creating lots of large objects if you can help it. In particular, slicing a list or string involves copying the entirety of the slice, so you shouldn't be taking large slices of anything in a loop.

1 month later

is there any test case with N=0 in this problem? if so, what should we output?

I don't know whether any such test case exists. If it does, the input and output for it would both just be an empty line.