結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー bayashiko_rbayashiko_r
提出日時 2019-08-01 14:46:55
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 1,000 ms
コード長 1,487 bytes
コンパイル時間 2,132 ms
コンパイル使用メモリ 106,852 KB
実行使用メモリ 22,872 KB
最終ジャッジ日時 2023-09-18 17:22:51
合計ジャッジ時間 5,488 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
22,872 KB
testcase_01 AC 57 ms
20,660 KB
testcase_02 AC 57 ms
22,776 KB
testcase_03 AC 57 ms
20,720 KB
testcase_04 AC 57 ms
20,772 KB
testcase_05 AC 57 ms
20,660 KB
testcase_06 AC 59 ms
20,696 KB
testcase_07 AC 57 ms
20,748 KB
testcase_08 AC 57 ms
20,692 KB
testcase_09 AC 57 ms
20,664 KB
testcase_10 AC 57 ms
20,748 KB
testcase_11 AC 57 ms
20,684 KB
testcase_12 AC 57 ms
18,728 KB
testcase_13 AC 57 ms
18,540 KB
testcase_14 AC 57 ms
20,840 KB
testcase_15 AC 57 ms
18,728 KB
testcase_16 AC 58 ms
22,696 KB
testcase_17 AC 57 ms
22,664 KB
testcase_18 AC 58 ms
22,680 KB
testcase_19 AC 57 ms
20,696 KB
testcase_20 AC 57 ms
20,728 KB
testcase_21 AC 57 ms
20,584 KB
testcase_22 AC 58 ms
20,680 KB
testcase_23 AC 57 ms
20,692 KB
testcase_24 AC 58 ms
22,684 KB
testcase_25 AC 57 ms
20,664 KB
testcase_26 AC 57 ms
20,708 KB
testcase_27 AC 56 ms
18,680 KB
testcase_28 AC 57 ms
20,752 KB
testcase_29 AC 58 ms
20,696 KB
testcase_30 AC 58 ms
20,600 KB
testcase_31 AC 58 ms
20,700 KB
testcase_32 AC 58 ms
20,696 KB
testcase_33 AC 57 ms
20,816 KB
testcase_34 AC 57 ms
18,660 KB
testcase_35 AC 58 ms
20,636 KB
testcase_36 AC 57 ms
20,740 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;
using System.Text;
using System.Threading.Tasks;

class Program {
    static void Main(string[] args) {
        //入力
        long N = long.Parse(Console.ReadLine());
        string s = Console.ReadLine();
        long a = long.Parse(s.Split(' ')[0]);
        long b = long.Parse(s.Split(' ')[1]);
        long c = long.Parse(s.Split(' ')[2]);

        //回答となる数値
        long ans = 0;

        long a_num = 0;  //aの倍数の個数
        long b_num = 0;  //bの倍数の個数
        long c_num = 0;  //cの倍数の個数

        long a_b_num = 0;
        long b_c_num = 0;
        long c_a_num = 0;

        long a_b_c_num = 0;

        //検証
        a_num = N / a;
        b_num = N / b;
        c_num = N / c;

        a_b_num = N / LCM(a, b);
        b_c_num = N / LCM(b, c);
        c_a_num = N / LCM(c, a);

        a_b_c_num = N / LCM(LCM(a, b), c);

        ans = a_num + b_num + c_num - (a_b_num + b_c_num + c_a_num) + a_b_c_num;

        //出力
        Console.WriteLine(ans);
    }

    //ユークリッドの互除法
    public static long GCD(long a, long b) {
        if (a < b) {
            return GCD(b, a);
        }

        while (b != 0) {
            long amari = a % b;
            a = b;
            b = amari;
        }
        return a;
    }

    //最小公倍数を求める
    public static long LCM(long a, long b) {
        return a * b / GCD(a, b);
    }
}
0