結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー grun1301grun1301
提出日時 2021-06-26 20:04:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,553 bytes
コンパイル時間 1,194 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 15:31:46
合計ジャッジ時間 2,245 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//https://yukicoder.me/problems/891

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>
#include <string.h>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

//区間(1,n)においてaの倍数がいくつあるか調べる、
ll count(ll n,ll a){
    return n/a;
}

ll gcd(ll a,ll b){
    if(a % b == 0) return b;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

int main(){
    ll n;
    vector<ll> a(3);
    cin >> n;
    //cin >> a >> b >> c;
    rep(i,3){
        cin >> a[i];
    }

    sort(a.begin(),a.end(),less<ll>());
    ll ans = 0;
    ll tmp1,tmp2;

    if(a[1] % a[0] == 0 && a[2] % a[0] ==0){
        ans = count(n,a[0]);
    }else if(a[1] % a[0] == 0){
        tmp1 = count(n,a[0]) + count(n,a[2]);
        tmp2 = count(n,lcm(a[0],a[2]));
        ans = tmp1-tmp2;
    }else if(a[2] % a[0] == 0 || a[2] % a[1] == 0){
        tmp1 = count(n,a[0]) + count(n,a[1]);
        tmp2 = count(n,lcm(a[0],a[1]) );
        ans = tmp1-tmp2;
    }else{
        tmp1 = count(n,a[0]) + count(n,a[1]) + count(n,a[2]);
        tmp2 = count(n,lcm(a[0],a[1]) ) + count(n,lcm(a[1],a[2])) + count(n,lcm(a[0],a[2]));
        
        ll tmp3 = lcm(a[0],a[1]);
        tmp3 = lcm(tmp3,a[2]);

        ans = tmp1 - tmp2 + count(n,tmp3);
    }

    cout << ans << endl;
    return 0;
}
0