結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー kyuna
提出日時 2019-08-19 07:56:25
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 680 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 71,408 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-02 07:57:20
合計ジャッジ時間 1,853 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
inline long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
    long long n; cin >> n;
    vector<int> a(3);
    for (int &ai: a) cin >> ai;
    long long ans = 0;
    for (int mask = 1; mask < 1 << 3; mask++) {
        long long _lcm = 1;
        for (int i = 0; i < 3; i++) if (mask >> i & 1) _lcm = lcm(_lcm, a[i]);
        if (__builtin_parity(mask)) {
            ans += n / _lcm;
        } else {
            ans -= n / _lcm;
        }
    }
    cout << ans << endl;
    return 0;
}
0