結果
| 問題 |
No.2847 Birthday Attack
|
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2024-08-23 23:29:46 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,018 ms / 3,000 ms |
| コード長 | 2,795 bytes |
| コンパイル時間 | 3,432 ms |
| コンパイル使用メモリ | 269,464 KB |
| 実行使用メモリ | 30,668 KB |
| 最終ジャッジ日時 | 2024-08-23 23:30:05 |
| 合計ジャッジ時間 | 17,777 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#if __INCLUDE_LEVEL__ == 0
#include __BASE_FILE__
using Mint = atcoder::modint;
Mint C2(int n) {
return n * int64_t(n - 1) / 2;
}
void Solve() {
int X, Y, M;
IN(X, Y, M);
Mint::set_mod(M);
Mint ans = 0;
for (int _ : Rep(0, 2)) {
ans += (C2(DivFloor(X, 2)) + C2(DivCeil(X, 2))) * Y;
vector<pair<int, int>> v;
for (int m : Rep(1, 1700)) {
for (int n : Rep(1, m)) {
int a = m * m - n * n;
int b = 2 * m * n;
int c = m * m + n * n;
if (gcd(gcd(a, b), c) == 1) {
v.emplace_back(a, b);
v.emplace_back(b, a);
}
}
}
ranges::sort(v);
APPLY(v.erase, ranges::unique(v));
for (auto [a, b] : v) {
for (int A = a, B = b; 2 * A < X && 2 * B < Y; A += a, B += b) {
ans += Mint(X - 2 * A) * Mint(Y - 2 * B);
}
}
swap(X, Y);
}
OUT(2 * ans);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}
#elif __INCLUDE_LEVEL__ == 1
#include <bits/stdc++.h>
#include <atcoder/modint>
template <class T> concept Range = std::ranges::range<T> && !std::convertible_to<T, std::string_view>;
template <class T> concept Tuple = std::__is_tuple_like<T>::value && !Range<T>;
namespace std {
istream& operator>>(istream& is, Range auto&& r) {
for (auto&& e : r) is >> e;
return is;
}
istream& operator>>(istream& is, Tuple auto&& t) {
apply([&](auto&... xs) { (is >> ... >> xs); }, t);
return is;
}
ostream& operator<<(ostream& os, Range auto&& r) {
auto sep = "";
for (auto&& e : r) os << exchange(sep, " ") << e;
return os;
}
ostream& operator<<(ostream& os, Tuple auto&& t) {
auto sep = "";
apply([&](auto&... xs) { ((os << exchange(sep, " ") << xs), ...); }, t);
return os;
}
template <class T, atcoder::internal::is_modint_t<T>* = nullptr>
istream& operator>>(istream& is, T& x) {
int v;
is >> v;
x = T::raw(v);
return is;
}
template <class T, atcoder::internal::is_modint_t<T>* = nullptr>
ostream& operator<<(ostream& os, const T& x) {
return os << x.val();
}
} // namespace std
using namespace std;
#define _ _ [[maybe_unused]]
#define LAMBDA(x, ...) [&](auto&& x) -> decltype(auto) { return __VA_ARGS__; }
#define LAMBDA2(x, y, ...) [&](auto&& x, auto&& y) -> decltype(auto) { return __VA_ARGS__; }
#define ALL(r) begin(r), end(r)
#define APPLY(f, r, ...) LAMBDA(_r, f(ALL(_r), ##__VA_ARGS__))(r)
#define Rep(...) [](int l, int r) { return views::iota(min(l, r), r); }(__VA_ARGS__)
#define DivFloor(...) LAMBDA2(x, y, x / y - ((x ^ y) < 0 && x % y != 0))(__VA_ARGS__)
#define DivCeil(...) LAMBDA2(x, y, x / y + ((x ^ y) >= 0 && x % y != 0))(__VA_ARGS__)
#define IN(...) cin >> forward_as_tuple(__VA_ARGS__)
#define OUT(...) cout << forward_as_tuple(__VA_ARGS__) << '\n'
#endif // __INCLUDE_LEVEL__ == 1
risujiroh