結果
| 問題 |
No.2128 Round up!!
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2022-11-18 22:17:31 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,140 bytes |
| コンパイル時間 | 1,752 ms |
| コンパイル使用メモリ | 168,400 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-20 02:38:49 |
| 合計ジャッジ時間 | 4,405 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 11 |
ソースコード
#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){
cntA++;
}
__int128_t ans = cntA + cntB - 1;
if (X % A != 0 && X % B != 0){
ans++;
}
cout << (int) (ans % MOD) << endl;
}
}
}
}
SSRS