結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー memmemmi
提出日時 2018-12-01 00:30:11
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,021 bytes
コンパイル時間 1,095 ms
コンパイル使用メモリ 111,672 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-26 23:49:24
合計ジャッジ時間 2,310 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){
    if(b==0)return a;
    else return gcd(b, a%b);
}

ll lcm(ll a, ll b){
    ll d = gcd(a, b);
    return a*b/d;
}

int main() {
    ll N; cin>>N;
    vector<ll> a(3); cin>>a[0]>>a[1]>>a[2];

    ll res=0;
    res+=N/a[0]+N/a[1]+N/a[2];

    ll d1 = lcm(a[0], a[1]), d2=lcm(a[1], a[2]), d3=lcm(a[2], a[0]), d=lcm(lcm(a[0], a[1]), a[2]);
    res-=N/d1+N/d2+N/d3;
    res+=N/d;

    cout<<res<<endl;

    return 0;
}
0