結果

問題 No.2128 Round up!!
ユーザー SSRSSSRS
提出日時 2022-11-18 22:18:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 1,561 ms
コンパイル使用メモリ 169,240 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 07:09:15
合計ジャッジ時間 4,240 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 89 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 102 ms
4,348 KB
testcase_04 AC 107 ms
4,348 KB
testcase_05 AC 135 ms
4,348 KB
testcase_06 AC 221 ms
4,348 KB
testcase_07 AC 169 ms
4,348 KB
testcase_08 AC 181 ms
4,348 KB
testcase_09 AC 101 ms
4,348 KB
testcase_10 AC 148 ms
4,348 KB
testcase_11 AC 149 ms
4,348 KB
testcase_12 AC 167 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 - X){
          cntA++;
        }
        __int128_t ans = cntA + cntB - 1;
        if (X % A != 0 && X % B != 0){
          ans++;
        }
        cout << (int) (ans % MOD) << endl;
      }
    }
  }
}
0