結果

問題 No.894 二種類のバス
ユーザー ponponpainfulponponpainful
提出日時 2019-09-27 22:29:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 844 bytes
コンパイル時間 2,364 ms
コンパイル使用メモリ 166,356 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-25 01:29:08
合計ジャッジ時間 2,383 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 1 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 2 ms
4,368 KB
testcase_13 AC 2 ms
4,368 KB
testcase_14 AC 2 ms
4,368 KB
testcase_15 AC 1 ms
4,368 KB
testcase_16 AC 2 ms
4,368 KB
testcase_17 AC 2 ms
4,368 KB
testcase_18 AC 1 ms
4,368 KB
testcase_19 AC 2 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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