結果

問題 No.894 二種類のバス
コンテスト
ユーザー ponponpainful
提出日時 2019-09-27 22:29:58
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 1,000 ms
+ 462µs
コード長 844 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 898 ms
コンパイル使用メモリ 178,708 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-09-03 11:22:30
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

template<typename T>
T gcd(T a, T b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}

template<typename T>
T lcm(T a, T b) {
  T ret = a / gcd(a, b) * b;
  if (b <= numeric_limits<T>::max() / (a / gcd(a, b))) return ret;
  else return numeric_limits<T>::max();
}

int main() {
  long long t, a, b; cin>>t>>a>>b;
  long long ans = 0;
  long long l = lcm(a, b);
  ans += (t-1)/a + (t-1)/b + 1;
  ans -= (t-1)/l;
  print(ans);

  return 0;
}
0