結果

問題 No.894 二種類のバス
ユーザー kobynkobyn
提出日時 2019-09-27 22:24:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,374 bytes
コンパイル時間 2,788 ms
コンパイル使用メモリ 200,732 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 23:47:46
合計ジャッジ時間 6,174 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'T gcd(T, T) [with T = long long int]':
main.cpp:64:8: warning: control reaches end of non-void function [-Wreturn-type]
   64 |     gcd(y, x % y);
      |     ~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

template <class T> T gcd(T x, T y) {
    // 最小公倍数を求める
    if (y == 0)
        return x;
    gcd(y, x % y);
}

template <class T> T lcm(T x, T y) {
    // 最大公約数を求める
    T GCD = gcd(x, y);
    T ans = x / GCD * y;
    return ans;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll T, A, B;
    scan(T, A, B);

    ll ans = T / A + T / B + 1;
    if (T % A == 0)
        ans--;
    if (T % B == 0)
        ans--;
    ll lc = lcm(A, B);
    ans -= T / lc;
    if (T % lc == 0)
        ans++;
    print(ans);

    return 0;
}
0