結果
| 問題 |
No.3133 法B逆元
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-02 21:43:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 882 bytes |
| コンパイル時間 | 1,661 ms |
| コンパイル使用メモリ | 192,288 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-05-02 21:43:57 |
| 合計ジャッジ時間 | 2,326 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:45:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘int’ [-Wformat=]
45 | printf("%lld\n", x);
| ~~~^ ~
| | |
| | int
| long long int
| %d
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f;
ll res;
int n, m, cnt, w[N];
inline void read(__int128 &X)
{
X = 0;
int w=0; char ch=0;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
if (w) X = -X;
}
int exgcd(int a, int b, int& x, int& y) {
if (!b) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
int main() {
ll n, b;
__int128 pn;
read(pn);
cin >> b;
n = pn % b;
if (__gcd(n, b) != 1) puts("NaN");
else {
int x, y;
exgcd(n, b, x, y);
ll lcm = b / __gcd(n, b);
x %= lcm;
x += lcm;
x %= lcm;
printf("%lld\n", x);
}
return 0;
}