結果
問題 | No.2847 Birthday Attack |
ユーザー |
|
提出日時 | 2024-08-23 23:23:56 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 209 ms / 3,000 ms |
コード長 | 1,941 bytes |
コンパイル時間 | 3,096 ms |
コンパイル使用メモリ | 246,488 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-08-23 23:24:02 |
合計ジャッジ時間 | 5,925 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> #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 <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0;} template <class T> 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; }