結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー 抹茶アイス抹茶アイス
提出日時 2023-07-27 11:33:56
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 1,160 bytes
コンパイル時間 9,785 ms
コンパイル使用メモリ 168,108 KB
実行使用メモリ 184,836 KB
最終ジャッジ日時 2024-04-14 23:51:14
合計ジャッジ時間 12,975 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
29,932 KB
testcase_01 AC 54 ms
29,952 KB
testcase_02 AC 53 ms
29,948 KB
testcase_03 AC 54 ms
29,940 KB
testcase_04 AC 53 ms
30,208 KB
testcase_05 AC 53 ms
29,824 KB
testcase_06 AC 53 ms
29,952 KB
testcase_07 AC 54 ms
29,952 KB
testcase_08 AC 53 ms
29,824 KB
testcase_09 AC 53 ms
30,208 KB
testcase_10 AC 53 ms
29,824 KB
testcase_11 AC 53 ms
29,824 KB
testcase_12 AC 54 ms
30,080 KB
testcase_13 AC 53 ms
29,952 KB
testcase_14 AC 54 ms
29,824 KB
testcase_15 AC 53 ms
30,072 KB
testcase_16 AC 53 ms
29,824 KB
testcase_17 AC 54 ms
30,080 KB
testcase_18 AC 54 ms
29,952 KB
testcase_19 AC 54 ms
29,952 KB
testcase_20 AC 54 ms
29,952 KB
testcase_21 AC 54 ms
29,696 KB
testcase_22 AC 54 ms
29,696 KB
testcase_23 AC 53 ms
29,952 KB
testcase_24 AC 53 ms
30,080 KB
testcase_25 AC 53 ms
29,824 KB
testcase_26 AC 54 ms
29,824 KB
testcase_27 AC 55 ms
29,696 KB
testcase_28 AC 54 ms
30,080 KB
testcase_29 AC 54 ms
29,696 KB
testcase_30 AC 53 ms
29,952 KB
testcase_31 AC 53 ms
29,940 KB
testcase_32 AC 54 ms
29,932 KB
testcase_33 AC 52 ms
29,696 KB
testcase_34 AC 53 ms
29,952 KB
testcase_35 AC 53 ms
29,952 KB
testcase_36 AC 53 ms
184,836 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (93 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace yukicoder
{
	public class Program
	{
		public static void Main()
		{
			var n = int.Parse(Console.ReadLine());
			var a = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
			if (a[1] % a[0] == 0 && a[2] % a[0] == 0)
			{
				Console.WriteLine(n / a[0]);
			}
			else if (a[1] % a[0] == 0)
			{
				Console.WriteLine(n / a[0] + n / a[2] - n / Lcm(a[0] , a[2]));
			}
			else if (a[2] % a[0] == 0 || a[2] % a[1] == 0)
            {
				Console.WriteLine(n / a[0] + n / a[1] - n / Lcm(a[0] , a[1]));
			}
            else
            {
				Console.WriteLine(n / a[0] + n / a[1] + n / a[2] - n / Lcm(a[0] , a[1]) - n / Lcm(a[1] , a[2]) - n / Lcm(a[0] , a[2]) + n / Lcm(a[0] , Lcm(a[1] , a[2])));
			}
		}
		public static long Lcm(long a, long b)
		{
			return a * b / Gcd(a, b);
		}

		// ユークリッドの互除法 
		public static long Gcd(long a, long b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}
0