結果

問題 No.2526 Kth Not-divisible Number
ユーザー 👑 chro_96chro_96
提出日時 2023-11-03 21:48:19
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 293 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 29,612 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 21:48:26
合計ジャッジ時間 4,568 ms
ジャッジサーバーID
(参考情報)
judge15 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 292 ms
4,348 KB
testcase_04 AC 293 ms
4,348 KB
testcase_05 AC 291 ms
4,348 KB
testcase_06 AC 290 ms
4,348 KB
testcase_07 AC 292 ms
4,348 KB
testcase_08 AC 261 ms
4,348 KB
testcase_09 AC 257 ms
4,348 KB
testcase_10 AC 266 ms
4,348 KB
testcase_11 AC 252 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long gcd (long long a, long long b) {
  if (b <= 0LL) {
    return a;
  }
  
  return gcd(b, a%b);
}

int main () {
  int t = 0;
  long long a = 0LL;
  long long b = 0LL;
  long long k = 0LL;
  
  int res = 0;
  
  res = scanf("%d", &t);
  while (t > 0) {
    long long lcm = 0LL;
    long long ans[2] = { 0LL, 4000000000000000000LL };
    res = scanf("%lld", &a);
    res = scanf("%lld", &b);
    res = scanf("%lld", &k);
    lcm = (a*b)/gcd(a, b);
    while (ans[1]-ans[0] > 1LL) {
      long long cnt = 0LL;
      long long nxt = (ans[0] + ans[1]) / 2LL;
      cnt = nxt/a;
      cnt += nxt/b;
      cnt -= nxt/lcm;
      if (nxt-cnt < k) {
        ans[0] = nxt;
      } else {
        ans[1] = nxt;
      }
    }
    printf("%lld\n", ans[1]);
    t--;
  }
  
  return 0;
}
0