結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー nanophoto12nanophoto12
提出日時 2015-12-13 08:42:53
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 66 ms / 1,000 ms
コード長 2,085 bytes
コンパイル時間 3,084 ms
コンパイル使用メモリ 106,884 KB
実行使用メモリ 23,768 KB
最終ジャッジ日時 2023-08-13 15:58:51
合計ジャッジ時間 5,906 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,556 KB
testcase_01 AC 65 ms
23,644 KB
testcase_02 AC 62 ms
23,620 KB
testcase_03 AC 64 ms
23,676 KB
testcase_04 AC 63 ms
19,588 KB
testcase_05 AC 63 ms
19,520 KB
testcase_06 AC 64 ms
21,796 KB
testcase_07 AC 64 ms
23,544 KB
testcase_08 AC 62 ms
19,528 KB
testcase_09 AC 64 ms
21,528 KB
testcase_10 AC 64 ms
23,640 KB
testcase_11 AC 64 ms
19,508 KB
testcase_12 AC 65 ms
19,580 KB
testcase_13 AC 65 ms
21,624 KB
testcase_14 AC 65 ms
21,692 KB
testcase_15 AC 63 ms
21,588 KB
testcase_16 AC 65 ms
21,740 KB
testcase_17 AC 66 ms
21,588 KB
testcase_18 AC 65 ms
21,740 KB
testcase_19 AC 65 ms
23,560 KB
testcase_20 AC 66 ms
21,524 KB
testcase_21 AC 66 ms
23,604 KB
testcase_22 AC 66 ms
23,684 KB
testcase_23 AC 65 ms
21,644 KB
testcase_24 AC 65 ms
21,656 KB
testcase_25 AC 64 ms
23,628 KB
testcase_26 AC 63 ms
21,604 KB
testcase_27 AC 64 ms
21,712 KB
testcase_28 AC 64 ms
23,628 KB
testcase_29 AC 64 ms
23,688 KB
testcase_30 AC 66 ms
21,596 KB
testcase_31 AC 65 ms
21,616 KB
testcase_32 AC 65 ms
23,768 KB
testcase_33 AC 64 ms
21,564 KB
testcase_34 AC 66 ms
21,708 KB
testcase_35 AC 66 ms
23,712 KB
testcase_36 AC 66 ms
21,664 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Linq;
using System.Text;

namespace No316
{
	class MainClass
	{
		private static long Pow(long value, long pow){
			long result = 1;
			for (int i = 0; i < pow; i++) {
				result *= value;
			}
			return result;
		}

		private static long Multiply(Dictionary<long, int> first, Dictionary<long, int> second){
			long value = 1;
			var firstCopy = new Dictionary<long, int> (first);
			var secondCopy = new Dictionary<long, int> (second);
			foreach (var keyValue in firstCopy) {
				long mul = keyValue.Value;
				if(secondCopy.ContainsKey(keyValue.Key)){
					mul = Math.Max(mul, secondCopy[keyValue.Key]);
					secondCopy.Remove (keyValue.Key);
				}
				value *= Pow (keyValue.Key, mul);
			}
			foreach (var keyValue in secondCopy) {
				value *= Pow (keyValue.Key, keyValue.Value);
			}
			return value;
		}

		private static Dictionary<long, int> Split(long value)
		{		
			var cache = value;
			Dictionary<long, int> dic = new Dictionary<long, int> ();	
			for (long i = 2; i * i <= cache; i++) {
				while (value % i == 0) {
					if (!dic.ContainsKey (i)) {
						dic.Add (i, 0);
					}
					dic [i]++;
					value /= i;
				}
			}
			if (value != 1) {
				dic.Add (value, 1);
			}
			return dic;
		}
			
		public static void Main (string[] args)
		{
			var n = Convert.ToInt64(Console.ReadLine ());
			var keys = Console.ReadLine ().Split(' ').Select(a=>Convert.ToInt64(a)).ToList();

			var aCount = n / keys [0];
			var bCount = n / keys [1];
			var cCount = n / keys [2];

			var aFactor = Split (keys [0]);
			var bFactor = Split (keys [1]);
			var cFactor = Split (keys [2]);

			var ab = Multiply (aFactor, bFactor);
			var bc = Multiply (bFactor, cFactor);
			var ca = Multiply (cFactor, aFactor);

			var abCount = n / ab;
			var bcCount = n / bc;
			var caCount = n / ca;

			var caFactor = Split (ca);
			var abc = Multiply (bFactor, caFactor);
					
			var abcCount = n / abc;

			var sum = aCount + bCount + cCount - abCount - bcCount - caCount + abcCount;

			Console.WriteLine(sum.ToString());
		}
	}
}
0