結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー nuwasoginuwasogi
提出日時 2015-12-13 14:47:06
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 1,895 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 117,248 KB
実行使用メモリ 27,348 KB
最終ジャッジ日時 2024-11-21 11:58:06
合計ジャッジ時間 2,838 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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;

namespace MottoFizzBuzz
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver sol = new Solver();
            sol.Solve();
        }
    }
    class Solver
    {
        int N;
        int[] ABC;
        int[] lcm;
        long lcm_abc;

        public void Solve()
        {
            int ans;
            ans = N / ABC[0] + N / ABC[1] + N / ABC[2] - N / lcm[0] - N / lcm[1] - N / lcm[2] + (int)(N / lcm_abc);
            Console.WriteLine(ans);
        }

        public Solver()
        {
            N = ri();
            ABC = ria();
            lcm = new int[] {(int)LCM(ABC[0], ABC[1]), (int)LCM(ABC[0], ABC[2]), (int)LCM(ABC[1], ABC[2]) };
            lcm_abc = LCM(lcm[0], ABC[2]);
        }

        public int GCD(int a, int b)
        {
            int q, r;
            while (true)
            {
                q = a / b;
                r = a % b;
                if (r == 0) break;
                a = b;
                b = r;
            }
            return b;
        }

        public long LCM(int a, int b)
        {
            long gcd = GCD(a, b);
            long lcm = (long)a * b / gcd;
            return lcm;
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }
}
0