結果

問題 No.3133 法B逆元
ユーザー sai
提出日時 2025-05-02 21:29:58
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 428 bytes
コンパイル時間 3,597 ms
コンパイル使用メモリ 277,740 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-02 21:30:03
合計ジャッジ時間 4,072 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/math>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  unsigned long long n;
  int b;
  std::cin >> n >> b;
  if (b == 1) {
    std::cout << "0\n";
    return 0;
  }
  if (n == 0) {
    std::cout << "NaN\n";
    return 0;
  }
  n %= b;
  if (std::gcd(n, b) == 1) {
    std::cout << atcoder::inv_mod(n, b) << '\n';
  } else {
    std::cout << "NaN\n";
  }
}
0