#include using ll = std::int64_t; using P = std::tuple; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); ll X, Y, M; std::cin >> X >> Y >> M; ll res = 0; for(ll x=1;x<=X;x++){ ll r = std::min(x - 1, X - x); res += 2ll * r * Y % M; if(res >= M){res -= M;} } for(ll y=1;y<=Y;y++){ ll r = std::min(y - 1, Y - y); res += 2ll * r * X % M; if(res >= M){res -= M;} } std::vector

v; ll Z = std::max(X, Y); for(ll a=1;a<=(Z-1)/2;a++){ for(ll b=1+a%2;b<=(Z-1)/2/a;b+=2){ if(a <= b){break;} if(std::gcd(a, b) > 1){continue;} ll c = a * a - b * b, d = 2ll * a * b; if(c < X && d < Y){ v.emplace_back(c, d); } if(c < Y && d < X){ v.emplace_back(d, c); } } } for(auto [c, d] : v){ for(int k=2;c*k= M){res -= M;} } } std::cout << res << std::endl; }