結果
| 問題 |
No.3179 3 time mod
|
| ユーザー |
|
| 提出日時 | 2025-06-13 21:50:34 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,621 bytes |
| コンパイル時間 | 3,562 ms |
| コンパイル使用メモリ | 253,880 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-13 21:50:43 |
| 合計ジャッジ時間 | 8,036 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 RE * 40 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using i32 = int;
using i64 = long long;
using f64 = long double;
using i128 = __int128_t;
using p2 = pair<i64, i64>;
using el = tuple<i64, i64, i64>;
using mint = atcoder::modint998244353;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
i64 pow(i64 x, i64 n, i64 m) {
i64 res = 1;
i64 t = x % m;
while (n > 0) {
if (n & 1) {
res = res * t % m;
}
t = t * t % m;
n >>= 1;
}
return res;
}
//https://qiita.com/drken/items/b97ff231e43bce50199a
// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
i128 extGCD(i128 a, i128 b, i128 &x, i128 &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
i128 d = extGCD(b, a%b, y, x);
y -= a/b * x;
return d;
}
void _main() {
i64 n, p, q, r, a, b, c;
cin >> n >> p >> q >> r >> a >> b >> c;
i128 x = p, y = a;
{
i128 s, t;
i128 g = extGCD(x, q, s, t);
assert(g == 1);
i128 C = b - y;
s *= C, t *= C;
assert(x * s + q * t == b - y);
assert(x * s + y == q * (-t) + b);
i128 V = x * s + y;
x = x * q, y = V;
y = (y % x + x) % x;
}
{
i128 s, t;
i128 g = extGCD(x, r, s, t);
assert(g == 1);
i128 C = c - y;
s *= C, t *= C;
assert(x * s + r * t == c - y);
assert(x * s + y == r * (-t) + c);
i64 V = x * s + y;
x = x * r, y = V;
y = (y % x + x) % x;
}
assert(y % p == a);
assert(y % q == b);
assert(y % r == c);
i64 ans = (n - y) / x + 1;
cout << ans << "\n";
}