from sys import argv n = int(argv[1]) total = 3 * n ** 2 if n % 2 == 0: total += n total += (n - 1) / 2 * n def gcd(x, y): if y == 0: return x return gcd(y, x % y) for i in xrange(1, n - 1): for j in xrange(i + 1, n + 1): d = gcd(i, j) i_ = i / d j_ = j / d total += min((n - i) / j_, j / i_) * 2 total += min((n - j) / i_, i / j_) * 2 print total