from math import gcd x, y, MOD = map(int, input().split()) ans = 0 lst = [] for n in range(1, 4000000): for m in range(n + 1, 4000000): a = m * m - n * n b = 2 * m * n c = m * m + n * n if b > max(x, y): break if gcd(a, b, c) == 1: lst.append((a, b, c)) ans = 0 ox = x // 2 ex = x - ox oy = y // 2 ey = y - oy ans += ox * (ox - 1) // 2 * y ans += ex * (ex - 1) // 2 * y ans += oy * (oy - 1) // 2 * x ans += ey * (ey - 1) // 2 * x ans %= MOD print(2 * ans % MOD) exit() for a, b, c in lst: k = min(x // a, y // b) for i in range(1, k + 1): ans += (x - a * i) * (y - b * i) % MOD k = min(x // b, y // a) for i in range(1, k + 1): ans += (x - b * i) * (y - a * i) % MOD ans %= MOD ans *= 2 print(ans % MOD)