結果

問題 No.316 もっと刺激的なFizzBuzzをください
コンテスト
ユーザー kyuna
提出日時 2019-08-19 07:56:25
言語 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
+ 370µs
コード長 680 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 423 ms
コンパイル使用メモリ 85,824 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2026-09-08 17:45:49
合計ジャッジ時間 2,407 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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