結果
問題 | No.2128 Round up!! |
ユーザー |
![]() |
提出日時 | 2022-11-18 22:18:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 220 ms / 2,000 ms |
コード長 | 1,144 bytes |
コンパイル時間 | 1,596 ms |
コンパイル使用メモリ | 168,392 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 02:41:49 |
合計ジャッジ時間 | 4,134 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std;const int MOD = 998244353;istream& operator >>(istream& is, __int128_t &x){string S;is >> S;x = 0;for (char c : S){x = x * 10 + (c - '0');}return is;}__int128_t gcd(__int128_t A, __int128_t B){if (B == 0){return A;} else {return gcd(B, A % B);}}__int128_t lcm(__int128_t A, __int128_t B){return A / gcd(A, B) * B;}int main(){int T;cin >> T;for (int i = 0; i < T; i++){__int128_t X, A, B;cin >> X >> A >> B;if (A == B){if (X % A == 0){cout << 1 << endl;} else {cout << 2 << endl;}} else {if (A > B){swap(A, B);}__int128_t L = lcm(A, B);X %= L;if (X == 0){cout << 1 << endl;} else {__int128_t cntB = (L - X) / B + 1;__int128_t cntA = cntB;if ((X + A - 1) / A * A - X < (X + B - 1) / B * B - X){cntA++;}__int128_t ans = cntA + cntB - 1;if (X % A != 0 && X % B != 0){ans++;}cout << (int) (ans % MOD) << endl;}}}}