結果

問題 No.2526 Kth Not-divisible Number
ユーザー chro_96chro_96
提出日時 2023-11-03 21:48:19
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 802 bytes
コンパイル時間 1,418 ms
コンパイル使用メモリ 29,056 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-25 19:57:26
合計ジャッジ時間 4,827 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

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