Just use memoisation up to the target value, for example. in Python:
class Memoize: def __init__(self, fn): self.fn = fn self.memo = {} def __call__(self, *args): if not self.memo.has_key(args): self.memo[args] = self.fn(*args) return self.memo[args] @Memoize def R(n): if n<=1: return 1 if n==2: return 2 n,rem = divmod(n,2) if rem: return R(n)+R(n-1)+1 return R(n)+R(n+1)+n
This instantly calculates the response to 10 ** 25.
The reason for this is that the nature of the recursion means that for the binary number abcdef, it will have to use no more values:
abcdef abcde-1,abcde,abcde+1 abcd-2,abcd-1,abcd,abcd+1,abcd+2 abc-2,abc-1,abc,abc+1,abc+2 ab-2,ab-1,ab,ab+1,ab+2 a-2,a-1,a,a+1,a+2
At each step, you can move up or down by 1, but you also divide the number by 2, so most of them can move away from the original number.
Therefore, memoised code will use no more than 5 * log_2 (n) ratings.