結果

問題 No.2128 Round up!!
ユーザー SSRSSSRS
提出日時 2022-11-18 22:17:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,140 bytes
コンパイル時間 1,948 ms
コンパイル使用メモリ 168,936 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-20 07:07:28
合計ジャッジ時間 4,274 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 164 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
      }
    }
  }
}
0