結果
| 問題 |
No.2847 Birthday Attack
|
| コンテスト | |
| ユーザー |
Yudai0606Nazo
|
| 提出日時 | 2025-08-03 08:02:23 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 332 ms / 3,000 ms |
| コード長 | 2,298 bytes |
| コンパイル時間 | 4,264 ms |
| コンパイル使用メモリ | 255,584 KB |
| 実行使用メモリ | 70,272 KB |
| 最終ジャッジ日時 | 2025-08-03 08:02:34 |
| 合計ジャッジ時間 | 10,275 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
#include <cassert>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint;
//using mint = modint998244353;
//using mint = modint1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repu(i, s, t) for (int i = (int)(s); i < (int)(t); i++)
#define repd(i, s, t) for (int i = (int)(s)-1; i >= (int)(t); i--)
#define all(v) v.begin(), v.end()
void _u() { cerr << endl; } template <class H, class... T> void _u(H&& h, T&&... t) { cerr << h << ", "; _u(move(t)...); }
#define U(...) { cerr << #__VA_ARGS__ << ": "; _u(__VA_ARGS__); }
template<typename T> bool chmax(T &a, const T b) { if(a >= b) return false; a = b; return true; }
template<typename T> bool chmin(T &a, const T b) { if(a <= b) return false; a = b; return true; }
template<typename T> istream& operator>>(istream &in, vector<T> &a) { for(T &x: a) in >> x; return in; }
template<typename T> ostream& operator<<(ostream &out, const vector<T> &a) { for(const T &x: a) out << x << ' '; return out; }
const int di[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dj[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int main() {
int x, y, m;
cin >> x >> y >> m;
mint::set_mod(m);
mint ans = 0;
auto calc1 = [&](int x, int y) -> mint {
int l = 3, r = ((x+1)>>1<<1)-1;
if(l > r) return 0;
mint res = mint(((x-l+1) + (x-r+1)) / 2) * ((r - l) / 2 + 1);
return res * y;
};
ans += calc1(x, y);
ans += calc1(y, x);
const int M = 1e6 + 10;
vector<pair<ll, ll>> pyth;
int cnt = 0;
for(int i = 1; i*i < M; i++) for(int j = i+1; i*j < M; j++) if(gcd(i, j) == 1 && ((~i&1) || (~j&1))) {
pyth.emplace_back(ll(j)*j-i*i, 2*i*j);
}
auto calc2 = [&](ll i, ll j) -> mint {
i *= 2, j *= 2;
if(x-1 < i || y-1 < j) return 0;
ll n = min((x-1)/i, (y-1)/j);
ll li = x-i*n, lj = y-j*n;
//(li+i*k)*(lj+j*k) = li*lj + (i*lj + j*li)*k + (i*j)*k^2
mint ans = mint(li)*lj*n + (mint(i)*lj + mint(j)*li)*(n*ll(n-1)/2) + mint(i)*j*mint(n*ll(n-1)*(2*n-1)/6);
return ans;
};
for(auto[i, j]: pyth) {
ans += calc2(i, j) * 2;
ans += calc2(j, i) * 2;
}
ans *= 2;
cout << ans.val() << endl;
return 0;
}
Yudai0606Nazo