結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー haruteruharuteru
提出日時 2016-01-25 14:45:01
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,827 bytes
コンパイル時間 543 ms
コンパイル使用メモリ 61,004 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 14:58:01
合計ジャッジ時間 1,653 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>

long long f(long long n1, long long n2)
{
    long long wk1 = n1;
    long long wk2 = n2;
    while (1) {
        if (wk1 == wk2) {
            break;
        }
        if (wk1 < wk2) {
            wk1 += n1;
        }
        else {
            wk2 += n2;
        }
    }
    return wk1;
}

int main()
{
    long long N;
    long long n[3] = {0};
    long long cnt = 0;
    long long d[6] = {0};

    std::cin >> N;
    std::cin >> n[0];
    std::cin >> n[1];
    std::cin >> n[2];
    std::sort(&n[0], &n[3]);

    for (int i = 0; i < 3; i++) {
        if (n[i] == 0) {
            std::cout << -1 << std::endl;
            return 0;
        }
        if (n[i] == 1) {
            std::cout << N << std::endl;
            return 0;
        }
    }

    cnt += N / n[0];
    cnt += N / n[2];
    cnt += N / n[1];

    d[0] = n[0];
    d[1] = n[1];
    d[2] = n[2];
    while (1) {
        if (d[0] > N && d[1] > N && d[2] > N) {
            break;
        }
        if (d[0] == d[1] &&
            d[1] == d[2] &&
            d[2] == d[0]) {
            break;
        }
        d[3] = f(d[0], d[1]);
        if (d[3] < N) {
            cnt -= N / d[3];
        }
        d[4] = f(d[1], d[2]);
        if (d[4] < N && d[3] != d[4]) {
            cnt -= N / d[4];
        }
        d[5] = f(d[2], d[0]);
        if (d[5] < N && d[3] != d[5] && d[4] != d[5]) {
            cnt -= N / d[5];
        }

        d[0] = f(d[3], d[4]);
        if (d[0] < N) {
            cnt += N / d[0];
        }
        d[1] = f(d[4], d[5]);
        if (d[1] < N && d[0] != d[1]) {
            cnt += N / d[1];
        }
        d[2] = f(d[5], d[3]);
        if (d[2] < N && d[0] != d[2] && d[1] != d[2]) {
            cnt += N / d[2];
        }
    }

    std::cout << cnt << std::endl;
    return 0;
}
0