結果
問題 | No.2847 Birthday Attack |
ユーザー | Fu_L |
提出日時 | 2024-08-23 22:52:35 |
言語 | C++23(gcc13) (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,019 ms / 3,000 ms |
コード長 | 5,253 bytes |
コンパイル時間 | 4,386 ms |
コンパイル使用メモリ | 283,892 KB |
実行使用メモリ | 54,272 KB |
最終ジャッジ日時 | 2024-08-23 22:52:58 |
合計ジャッジ時間 | 20,811 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 766 ms
54,144 KB |
testcase_01 | AC | 754 ms
54,272 KB |
testcase_02 | AC | 762 ms
54,144 KB |
testcase_03 | AC | 796 ms
54,144 KB |
testcase_04 | AC | 773 ms
54,144 KB |
testcase_05 | AC | 1,019 ms
54,144 KB |
testcase_06 | AC | 893 ms
54,144 KB |
testcase_07 | AC | 961 ms
54,016 KB |
testcase_08 | AC | 839 ms
54,144 KB |
testcase_09 | AC | 903 ms
54,144 KB |
testcase_10 | AC | 865 ms
54,144 KB |
testcase_11 | AC | 748 ms
54,272 KB |
testcase_12 | AC | 950 ms
54,144 KB |
testcase_13 | AC | 935 ms
54,272 KB |
testcase_14 | AC | 866 ms
54,144 KB |
testcase_15 | AC | 914 ms
54,016 KB |
testcase_16 | AC | 893 ms
54,144 KB |
testcase_17 | AC | 902 ms
54,016 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; #define rep(i, a, b) for(ll i = a; i < b; ++i) #define rrep(i, a, b) for(ll i = a; i >= b; --i) constexpr ll inf = 4e18; struct SetupIO { SetupIO() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(30); } } setup_io; struct Barrett { explicit Barrett(unsigned int m) : _m(m), im((unsigned long long)(-1) / m + 1) {} inline unsigned int umod() const { return _m; } inline unsigned int mul(unsigned int a, unsigned int b) const { unsigned long long z = a; z *= b; unsigned long long x = (unsigned long long)(((unsigned __int128)(z)*im) >> 64); unsigned int v = (unsigned int)(z - x * _m); if(_m <= v) v += _m; return v; } private: unsigned int _m; unsigned long long im; }; template <int id> struct DynamicModint { using mint = DynamicModint; static int mod() { return (int)bt.umod(); } static void set_mod(int m) { assert(1 <= m); bt = Barrett(m); } static mint raw(int v) { mint a; a._v = v; return a; } DynamicModint() : _v(0) {} template <class T> DynamicModint(const T& v) { static_assert(is_integral_v<T>); if(is_signed_v<T>) { long long x = (long long)(v % (long long)(umod())); if(x < 0) x += umod(); _v = (unsigned int)(x); } else _v = (unsigned int)(v % umod()); } unsigned int val() const { return _v; } mint& operator++() { ++_v; if(_v == umod()) _v = 0; return *this; } mint& operator--() { if(_v == 0) _v = umod(); --_v; return *this; } mint operator++(int) { mint res = *this; ++*this; return res; } mint operator--(int) { mint res = *this; --*this; return res; } mint& operator+=(const mint& rhs) { _v += rhs._v; if(_v >= umod()) _v -= umod(); return *this; } mint& operator-=(const mint& rhs) { _v += mod() - rhs._v; if(_v >= umod()) _v -= umod(); return *this; } mint& operator*=(const mint& rhs) { _v = bt.mul(_v, rhs._v); return *this; } mint& operator/=(const mint& rhs) { return *this *= rhs.inv(); } mint operator+() const { return *this; } mint operator-() const { return mint() - *this; } mint pow(long long n) const { assert(0 <= n); if(n == 0) return 1; mint x = *this, r = 1; while(1) { if(n & 1) r *= x; n >>= 1; if(n == 0) return r; x *= x; } } mint inv() const { auto eg = inv_gcd(_v, mod()); assert(eg.first == 1); return eg.second; } friend mint operator+(const mint& lhs, const mint& rhs) { return mint(lhs) += rhs; } friend mint operator-(const mint& lhs, const mint& rhs) { return mint(lhs) -= rhs; } friend mint operator*(const mint& lhs, const mint& rhs) { return mint(lhs) *= rhs; } friend mint operator/(const mint& lhs, const mint& rhs) { return mint(lhs) /= rhs; } friend bool operator==(const mint& lhs, const mint& rhs) { return lhs._v == rhs._v; } friend bool operator!=(const mint& lhs, const mint& rhs) { return lhs._v != rhs._v; } friend istream& operator>>(istream& in, mint& x) { long long a; in >> a; x = a; return in; } friend ostream& operator<<(ostream& out, const mint& x) { return out << x.val(); } private: unsigned int _v = 0; static Barrett bt; inline static unsigned int umod() { return bt.umod(); } inline static pair<long long, long long> inv_gcd(long long a, long long b) { if(a == 0) return {b, 0}; long long s = b, t = a, m0 = 0, m1 = 1; while(t) { const long long u = s / t; s -= t * u; m0 -= m1 * u; swap(s, t); swap(m0, m1); } if(m0 < 0) m0 += b / s; return {s, m0}; } }; template <int id> Barrett DynamicModint<id>::bt(998244353); using modint = DynamicModint<-1>; using mint = modint; int main(void) { ll x, y, m; cin >> x >> y >> m; mint::set_mod(m); mint ans = 0; for(ll r = 2; r <= max(x, y); r += 2) { ans += 2 * max(x - r, 0ll) * y + 2 * max(y - r, 0ll) * x; } set<tuple<ll, ll, ll>> st; rep(m, 1, 2000) { rep(n, 1, m) { if(gcd(n, m) != 1) continue; if(n % 2 == m % 2) continue; ll a = m * m - n * n; ll b = 2 * m * n; ll c = m * m + n * n; st.insert({a, b, c}); } } for(const auto& [a, b, c] : st) { for(ll i = 1; c * i <= max(x, y); i++) { ans += 4 * max(x - 2 * i * a, 0ll) * max(y - 2 * i * b, 0ll); ans += 4 * max(x - 2 * i * b, 0ll) * max(y - 2 * i * a, 0ll); } } cout << ans << '\n'; }