#include #define rep(i, p, n) for (ll i = p; i < (ll)(n); i++) #define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--) using namespace std; using ll = long long; using ld = long double; const double pi = 3.141592653589793; const long long inf = 2 * 1e9; const long long linf = 4 * 1e18; const ll mod1 = 1000000007; const ll mod2 = 998244353; template inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0;} template inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int main() { ////////////////// ios::sync_with_stdio(false); cin.tie(nullptr); ////////////////// ll X, Y, M; cin >> X >> Y >> M; ll ans = 0; ll x = X; x -= 2; while(x>0) { ans += x * Y; ans %= M; x -= 2; } ll y = Y; y -= 2; while(y>0) { ans += y * X; ans %= M; y -= 2; } rep(i, 2, 2001) { rep(j, 1, i) { if (!((i%2)^(j%2))) { continue; } if (gcd(i, j)!=1) { continue; } ll A = i * i - j * j; ll B = 2 * i * j; ll now = 1, sum=0; while (true) { sum=0; ll a = A * 2 * now; ll b = B * 2 * now; ll c = X - a; ll d = Y - b; if (c>0 && d>0) { sum += c * d * 2; } c = Y - a; d = X - b; if (c>0 && d>0) { sum += c * d * 2; } if (sum == 0) { break; } ans += sum; ans %= M; now++; } } } ans*=2; ans %= M; cout << ans; }