import math


def reverse(n):
    """
    Given integer n, returns n written backwards.
    Note: uses only numerical operations (not string ones) for speed.
    """
    d, r = 0, 0
    while n > 0:
        l = int(math.log10(n))
        r += (10 ** d) * (n // (10 ** (l)))
        d += 1
        n %= (10**l)
    return r