結果

問題 No.2847 Birthday Attack
ユーザー risujirohrisujiroh
提出日時 2024-08-23 23:29:46
言語 C++23
(gcc 12.3.0 + boost 1.83.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
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 596 ms
29,568 KB
testcase_01 AC 570 ms
28,852 KB
testcase_02 AC 594 ms
28,860 KB
testcase_03 AC 572 ms
29,360 KB
testcase_04 AC 594 ms
30,668 KB
testcase_05 AC 1,018 ms
29,712 KB
testcase_06 AC 772 ms
28,980 KB
testcase_07 AC 963 ms
29,476 KB
testcase_08 AC 694 ms
29,200 KB
testcase_09 AC 777 ms
28,872 KB
testcase_10 AC 731 ms
30,260 KB
testcase_11 AC 610 ms
28,760 KB
testcase_12 AC 932 ms
29,628 KB
testcase_13 AC 962 ms
29,548 KB
testcase_14 AC 818 ms
30,452 KB
testcase_15 AC 745 ms
29,776 KB
testcase_16 AC 768 ms
29,252 KB
testcase_17 AC 664 ms
29,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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
0