結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー akichiakichi
提出日時 2017-08-27 23:40:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 597 ms / 1,000 ms
コード長 1,369 bytes
コンパイル時間 1,865 ms
コンパイル使用メモリ 105,600 KB
実行使用メモリ 306,500 KB
最終ジャッジ日時 2024-04-24 00:30:41
合計ジャッジ時間 4,891 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
28,928 KB
testcase_01 AC 33 ms
24,064 KB
testcase_02 AC 28 ms
19,968 KB
testcase_03 AC 27 ms
20,096 KB
testcase_04 AC 26 ms
20,096 KB
testcase_05 AC 27 ms
20,096 KB
testcase_06 AC 27 ms
20,224 KB
testcase_07 AC 28 ms
20,224 KB
testcase_08 AC 28 ms
20,096 KB
testcase_09 AC 26 ms
19,968 KB
testcase_10 AC 26 ms
20,096 KB
testcase_11 AC 27 ms
19,968 KB
testcase_12 AC 27 ms
19,904 KB
testcase_13 AC 27 ms
20,160 KB
testcase_14 AC 27 ms
20,156 KB
testcase_15 AC 27 ms
20,028 KB
testcase_16 AC 43 ms
28,544 KB
testcase_17 AC 26 ms
20,284 KB
testcase_18 AC 28 ms
20,480 KB
testcase_19 AC 34 ms
23,808 KB
testcase_20 AC 36 ms
23,808 KB
testcase_21 AC 40 ms
27,648 KB
testcase_22 AC 29 ms
20,416 KB
testcase_23 AC 30 ms
21,504 KB
testcase_24 AC 28 ms
20,284 KB
testcase_25 AC 61 ms
35,968 KB
testcase_26 AC 28 ms
20,096 KB
testcase_27 AC 27 ms
20,224 KB
testcase_28 AC 27 ms
20,176 KB
testcase_29 AC 30 ms
21,632 KB
testcase_30 AC 61 ms
36,736 KB
testcase_31 AC 28 ms
20,176 KB
testcase_32 AC 505 ms
168,052 KB
testcase_33 AC 597 ms
306,500 KB
testcase_34 AC 42 ms
27,264 KB
testcase_35 AC 65 ms
37,888 KB
testcase_36 AC 227 ms
94,332 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
class Program {
    static void Main() {
        long n = long.Parse(Console.ReadLine());
        long[] abc = Console.ReadLine().Split().Select(long.Parse).ToArray();
        long lcm = Lcm(Lcm(abc[0], abc[1]), abc[2]);
        long ans = 0;
        if (lcm < n) {
            HashSet<int> hit = new HashSet<int>();

            foreach (int i in abc) {
                for (int j = i; j <= lcm; j += i) {
                    hit.Add(j);
                }
            }
            ans += hit.Count * (n / lcm);
        }

        long m = n % lcm;

        HashSet<int> hit2 = new HashSet<int>();
        foreach (int i in abc) {
            for (int j = i; j <= m; j += i) {
                hit2.Add(j);
            }
        }
        ans += hit2.Count;
        Console.WriteLine(ans);
    }

    // 最小公倍数 出典: http://qiita.com/gushwell/items/f08d0e71fa0480dbb396
    public static long Lcm(long a, long b) {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b) {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0) {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}
0