結果

問題 No.2526 Kth Not-divisible Number
ユーザー tnakao0123tnakao0123
提出日時 2023-11-08 19:21:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 346 ms / 2,000 ms
コード長 949 bytes
コンパイル時間 324 ms
コンパイル使用メモリ 41,536 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-08 19:22:05
合計ジャッジ時間 5,244 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 346 ms
6,676 KB
testcase_04 AC 346 ms
6,676 KB
testcase_05 AC 345 ms
6,676 KB
testcase_06 AC 346 ms
6,676 KB
testcase_07 AC 346 ms
6,676 KB
testcase_08 AC 317 ms
6,676 KB
testcase_09 AC 269 ms
6,676 KB
testcase_10 AC 313 ms
6,676 KB
testcase_11 AC 264 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2526.cc:  No.2526 Kth Not-divisible Number - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

template <typename T>
T gcd(T m, T n) {  // m >= 0, n >= 0
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}

template <typename T>
T lcm(T m, T n) {
  return m * n / gcd<T>(m, n);
}

/* main */

int main() {
  int tn;
  scanf("%d", &tn);

  while (tn--) {
    int a, b;
    ll k;
    scanf("%d%d%lld", &a, &b, &k);

    ll l = lcm<ll>(a, b);
    ll r = l - l / a - l / b + 1;
    //printf("r=%lld\n", r);

    ll x0 = 0, x1 = 4000000000000000000LL;
    while (x0 + 1 < x1) {
      ll x = (x0 + x1) / 2;
      ll y = x % l;
      if (x / l * r + (y - y / a - y / b) >= k) x1 = x;
      else x0 = x;
    }

    printf("%lld\n", x1);
  }
  return 0;
}
0