結果
| 問題 | No.2117 中国剰余定理入門 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-11-06 21:58:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 702 bytes |
| コンパイル時間 | 1,849 ms |
| コンパイル使用メモリ | 165,848 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-20 09:13:39 |
| 合計ジャッジ時間 | 2,867 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 RE * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int inv(int a, int m)
{
int m0 = m, t, q;
int x0 = 0, x1 = 1;
if (m == 1)
return 0;
while (a > 1) {
q = a / m;
t = m;
m = a % m, a = t;
t = x0;
x0 = x1 - q * x0;
x1 = t;
}
if (x1 < 0)
x1 += m0;
return x1;
}
int main() {
int b0, c0, b1, c1;
scanf("%d %d %d %d", &b0, &c0, &b1, &c1);
while (c0 < 0)
c0 += b0;
while (c1 < 0)
c1 += b1;
if (abs(c1 - c0) % __gcd(b1, b0) != 0)
cout << "NaN";
else {
int res = (c0 * b1 * inv(b1, b0) + c1 * b0 * inv(b0, b1)) % (b0 * b1);
cout << res;
}
return 0;
}