結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー kenken
提出日時 2018-07-16 13:24:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 1,000 ms
コード長 1,223 bytes
コンパイル時間 5,391 ms
コンパイル使用メモリ 104,704 KB
実行使用メモリ 25,728 KB
最終ジャッジ日時 2023-08-10 20:12:18
合計ジャッジ時間 9,888 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,628 KB
testcase_01 AC 60 ms
21,716 KB
testcase_02 AC 58 ms
21,776 KB
testcase_03 AC 59 ms
21,792 KB
testcase_04 AC 60 ms
21,664 KB
testcase_05 AC 59 ms
21,636 KB
testcase_06 AC 59 ms
21,644 KB
testcase_07 AC 62 ms
21,652 KB
testcase_08 AC 61 ms
19,620 KB
testcase_09 AC 60 ms
23,676 KB
testcase_10 AC 59 ms
21,664 KB
testcase_11 AC 60 ms
21,660 KB
testcase_12 AC 58 ms
23,696 KB
testcase_13 AC 61 ms
21,652 KB
testcase_14 AC 62 ms
21,616 KB
testcase_15 AC 61 ms
21,672 KB
testcase_16 AC 61 ms
21,652 KB
testcase_17 AC 57 ms
23,752 KB
testcase_18 AC 61 ms
21,808 KB
testcase_19 AC 63 ms
21,652 KB
testcase_20 AC 64 ms
21,608 KB
testcase_21 AC 62 ms
21,612 KB
testcase_22 AC 62 ms
21,716 KB
testcase_23 AC 60 ms
21,648 KB
testcase_24 AC 65 ms
21,764 KB
testcase_25 AC 61 ms
19,708 KB
testcase_26 AC 62 ms
23,632 KB
testcase_27 AC 63 ms
23,680 KB
testcase_28 AC 61 ms
23,696 KB
testcase_29 AC 61 ms
21,712 KB
testcase_30 AC 63 ms
23,748 KB
testcase_31 AC 61 ms
23,588 KB
testcase_32 AC 61 ms
23,684 KB
testcase_33 AC 59 ms
21,656 KB
testcase_34 AC 58 ms
23,692 KB
testcase_35 AC 59 ms
21,792 KB
testcase_36 AC 59 ms
25,728 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.Linq;

public class CountDivisors{
    static long GCD(long a, long b) {return (b == 0) ? a : GCD(b, a % b);}
    static long LCM(long a, long b) {return a / GCD(a, b) * b;}
    
    public static void Main(){
        var n = long.Parse(Console.ReadLine());
        var input = Console.ReadLine();
        var inputArr = input.Split(' ');
        var a = inputArr.Select(s => long.Parse(s)).ToArray();
        Array.Sort(a);
        for(var i = 0; i < 2; i++){
            if(a[2]%a[i] == 0){
                a[2] = a[i];
            }
        }
        for(var j = 2; j > 0; j--){
            if(a[j]%a[0] == 0){
                a[j] = a[0];
            }
        }
        var divArray = a.Distinct().ToArray();
        long numOfDivs = 0;
        
        foreach(var x in divArray){
            numOfDivs += n/x;
        }
        var len = divArray.Length;
        if(len == 3){
            numOfDivs += n / LCM(divArray[0], LCM(divArray[1], divArray[2]));
        }
        for(var i = 0; i < len; i++){
            for(var j = len-1; j > i; j--){
                numOfDivs -= n / LCM(divArray[i], divArray[j]);
            }
        }
        
        Console.WriteLine(numOfDivs);
    }
}
0