結果

問題 No.894 二種類のバス
ユーザー yuppe19 😺
提出日時 2019-09-28 08:53:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 755 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 33,024 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-01 13:02:14
合計ジャッジ時間 1,251 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdint>
#include <cstdlib>
using namespace std;
using u64 = uint64_t;

u64 gcd(u64 a, u64 b) {
  if(b == 0) { return a; }
  return gcd(b, a%b);
}

__uint128_t lcm(u64 a, u64 b) { return static_cast<__uint128_t>(a) * b / gcd(a, b); }

void puts_uint128(__uint128_t x) {
  size_t n = 0;
  char buf[64];
  do {
    buf[n++] = static_cast<char>(x % 10 + '0');
    x /= 10;
  } while(x != 0);
  buf[n] = '\0';
  char *r = reinterpret_cast<char*>(malloc(n * sizeof(char)));
  for(size_t i=0; i<n; ++i) {
    r[n-1-i] = buf[i];
  }
  puts(r);
  free(r);
}

int main(void) {
  u64 t, a, b; scanf("%lu%lu%lu", &t, &a, &b);
  --t;
  __uint128_t l = lcm(a, b);
  __uint128_t res = t/a + t/b - t/l + 1;
  puts_uint128(res);
  return 0;
}
0