結果

問題 No.2406 Difference of Coordinate Squared
ユーザー 👑 amentorimaruamentorimaru
提出日時 2023-07-12 01:42:46
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 869 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 129,280 KB
実行使用メモリ 7,152 KB
最終ジャッジ日時 2024-11-26 17:53:06
合計ジャッジ時間 2,583 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <math.h>
#include <atcoder/modint.hpp>

using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;

int main() {
  ll n, m;
  cin >> n >> m;
  m = abs(m);
  mint ans = 0;
  vector<mint> f(n + 1, 1);
  for (ll i = 0; i < n; i++)
    f[i + 1] = f[i] * (i + 1);
  for (ll y = 0; y < n; y++) {
    ll x2 = y * y + m;
    ll x = max(ll(sqrt(x2) - 2), 0LL);
    while (x * x - y * y < m)
      x++;
    if (x * x - y * y != m)
      continue;
    if ((n - x - y) % 2)
      continue;
    if (n - x - y < 0)
      break;
    ll a = abs(n - x + y) / 2;
    ll b = abs(n - x - y) / 2;
    mint tmp = f[n] * f[n] / (f[a] * f[n - a] * f[b] * f[n - b]);
    if (y)
      tmp *= 2;
    if (x)
      tmp *= 2;
    ans += tmp;
  }
  ans /= mint(4).pow(n);
  cout << ans.val() << "\n";
  return 0;
}
0