結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー hogeki
提出日時 2016-11-13 16:38:50
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 25 ms / 1,000 ms
コード長 758 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 110,200 KB
実行使用メモリ 18,048 KB
最終ジャッジ日時 2024-11-25 21:57:04
合計ジャッジ時間 2,681 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;

class SuperFizzBuzz
{
	static public void Main(string[] args)
	{
		long N, a, b, c;
		string[] abc;
		long count = 0;
		N = long.Parse(Console.ReadLine());
		abc = Console.ReadLine().Split(' ');
		a = long.Parse(abc[0]);
		b = long.Parse(abc[1]);
		c = long.Parse(abc[2]);
		long lcm_ab = lcm(a, b);
		long lcm_ac = lcm(a, c);
		long lcm_bc = lcm(b, c);
		long lcm_abc = lcm(lcm_ab, lcm_bc);
		count = N / a + N / b + N / c - N / lcm_ab - N / lcm_ac - N / lcm_bc + N / lcm_abc;
		Console.WriteLine(count);
	}

	static long gcd(long x, long y)
	{
		long t;
		if(x < y)
		{
			t = x;
			x = y;
			y = t;
		}
		if(x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	static long lcm(long x, long y)
	{
		return (x * y) / gcd(x, y);
	}
}
0