namespace AtCoder; #nullable enable using System.Numerics; static class Extensions { public static T[] Repeat(this int time, Func F) => Enumerable.Range(0, time).Select(_ => F()).ToArray(); } class AtCoder { object? Solve() { var x = Int(); var y = Int(); var z = Math.Max(x, y); var m = Int(); var ans = 0L; long GCD(long i, long j) => j == 0 ? i : GCD(j, i % j); long F(long a, long b) { Int128 t = Int128.MaxValue; if (a > 0) { var sx = x / a; if (sx < t) t = sx; } if (b > 0) { var sy = y / b; if (sy < t) t = sy; } var res = t * x * y % m; var t2 = t * (t + 1) * (t * 2 + 1) / 6 % m; var t1 = t * (t + 1) / 2 % m; res += t2 * a * b - t1 * (x * b + y * a); res %= m; if (res < 0) res += m; return (long)res; } for (var i = 0L; i <= z; i++) for (var j = 0L; j < i; j++) { if ((i + j) % 2 == 0) continue; var au = i * j * 2 * 2; var bu = (i * i - j * j) * 2; if (x < au && y < au && x < bu && y < bu) break; if (GCD(i, j) != 1) continue; ans = (ans + F(au, bu) + F(bu, au)) % m; } return ans * 2 % m; } public static void Main() => new AtCoder().Run(); public void Run() { var res = Solve(); if (res != null) { if (res is bool yes) res = yes ? "Yes" : "No"; sw.WriteLine(res); } sw.Flush(); } string[] input = Array.Empty(); int iter = 0; readonly StreamWriter sw = new(Console.OpenStandardOutput()) { AutoFlush = false }; string String() { while (iter >= input.Length) (input, iter) = (Console.ReadLine()!.Split(' '), 0); return input[iter++]; } T Input() where T : IParsable => T.Parse(String(), null); int Int() => Input(); void Out(object? x, string? separator = null) { separator ??= Environment.NewLine; if (x is System.Collections.IEnumerable obj and not string) { var firstLine = true; foreach (var item in obj) { if (!firstLine) sw.Write(separator); firstLine = false; sw.Write(item); } } else sw.Write(x); sw.WriteLine(); } }