Comment Comment by raoof if you don't want to melt your brain :D you just precompute the value of any functions f(x) for x<n otherwise you need to be very clever I explained my idea in the link parent raoof 2 years ago