from tools import number_theory

def cnt_side(limit):
    return limit ** 2 * 3

def cnt_cross(limit):
    return (limit - 1) // 2 * limit + (1 - limit % 2) * limit

def cnt_inner(limit):
    tale = 0
    for y in range(1, limit - 1):
        for x in range(y + 1, limit + 1):
            d = number_theory.gcd(x, y)
            dx = x // d
            dy = y // d
            tale += min((limit - x) // dy, y // dx)
            tale += min((limit - y) // dx, x // dy)
    return 2 * tale

def count(limit):
    return cnt_side(limit) + cnt_cross(limit) + cnt_inner(limit)

print(count(50))