結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー No
提出日時 2018-01-28 04:18:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 30 ms / 1,000 ms
コード長 1,277 bytes
コンパイル時間 1,809 ms
コンパイル使用メモリ 104,192 KB
実行使用メモリ 18,176 KB
最終ジャッジ日時 2024-12-29 08:17:20
合計ジャッジ時間 3,166 ms
ジャッジサーバーID
(参考情報)
judge1 / 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;

namespace y
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = decimal.Parse(Console.ReadLine());
            var ss = Console.ReadLine().Split();
            var an = decimal.Parse(ss[0]);
            var bn = decimal.Parse(ss[1]);
            var cn = decimal.Parse(ss[2]);
            decimal a = Math.Floor(n / an);
            decimal b = Math.Floor(n / bn);
            decimal c = Math.Floor(n / cn);

            decimal ab = Math.Floor(n / (an * bn / Gcd(an, bn)));
            decimal bc = Math.Floor(n / (bn * cn /Gcd(bn, cn)));
            decimal ac = Math.Floor(n / (an * cn / Gcd(an, cn)));
            decimal g = bn * cn / Gcd(bn, cn);
            decimal abc = Math.Floor( n / (an * g / Gcd(an,g)));

            decimal ab_c = ab - abc;
            decimal bc_a = bc - abc;
            decimal ac_b = ac - abc;

            decimal ans = (a + b + c) - ab - bc - ac + abc;

            Console.WriteLine(ans);
        }

        public static decimal Gcd(decimal a, decimal b)
        {
            if (a < b) return Gcd(b, a);
            while (b != 0)
            {
                var c = a % b;
                a = b;
                b = c;
            }
            return a;
        }
    }
}
0