結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー ken
提出日時 2018-07-16 13:24:22
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 33 ms / 1,000 ms
コード長 1,223 bytes
コンパイル時間 4,154 ms
コンパイル使用メモリ 116,876 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-11-17 05:33:53
合計ジャッジ時間 6,274 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます
コンパイルメッセージ
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