// #ifdef NACHIA // #define _GLIBCXX_DEBUG // #else // #define NDEBUG // #endif #include #include #include #include using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i void chmin(A& l, const A& r){ if(r < l) l = r; } template void chmax(A& l, const A& r){ if(l < r) l = r; } #include using Modint = atcoder::static_modint<998244353>; using namespace std; void testcase(){ i64 X, Y, M; cin >> X >> Y >> M; if(X < Y) swap(X, Y); i64 ans = 0; vector> pytha; for(i64 n=1; n<=X; n++) for(i64 m=0; m Y || max(a, b) > X) break; pytha.push_back({ min(a,b), max(a,b) }); } } sort(pytha.begin(), pytha.end()); pytha.erase(unique(pytha.begin(), pytha.end()), pytha.end()); for(auto [u,v] : pytha){ // cout << "u = " << u << " , v = " << v << endl; ans += max(0, X - u) * max(0, Y - v) * 2 % M; ans += max(0, Y - u) * max(0, X - v) * 2 % M; } ans %= M; cout << ans << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); testcase(); return 0; }