結果

問題 No.316 もっと刺激的なFizzBuzzをください
ユーザー nanophoto12nanophoto12
提出日時 2015-12-09 00:31:04
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,928 bytes
コンパイル時間 3,547 ms
コンパイル使用メモリ 104,984 KB
実行使用メモリ 23,880 KB
最終ジャッジ日時 2023-10-12 22:23:17
合計ジャッジ時間 6,911 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
21,696 KB
testcase_01 AC 65 ms
21,772 KB
testcase_02 AC 61 ms
21,720 KB
testcase_03 AC 63 ms
21,720 KB
testcase_04 AC 65 ms
21,808 KB
testcase_05 WA -
testcase_06 AC 65 ms
21,652 KB
testcase_07 WA -
testcase_08 AC 65 ms
23,784 KB
testcase_09 AC 65 ms
23,792 KB
testcase_10 AC 65 ms
21,648 KB
testcase_11 WA -
testcase_12 AC 67 ms
23,816 KB
testcase_13 AC 64 ms
21,696 KB
testcase_14 AC 65 ms
21,748 KB
testcase_15 AC 65 ms
23,624 KB
testcase_16 AC 66 ms
21,756 KB
testcase_17 AC 66 ms
23,672 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 66 ms
23,692 KB
testcase_24 AC 65 ms
23,772 KB
testcase_25 AC 65 ms
21,764 KB
testcase_26 AC 64 ms
23,800 KB
testcase_27 AC 63 ms
21,644 KB
testcase_28 AC 65 ms
21,756 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 No316t
{
	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;
			foreach (var keyValue in first) {
				int mul = keyValue.Value;
				if(second.ContainsKey(keyValue.Key)){
					mul = Math.Max(mul, second[keyValue.Key]);
					second.Remove (keyValue.Key);
				}
				value *= Pow (keyValue.Key, mul);
			}
			foreach (var keyValue in second) {
				value *= Pow (keyValue.Key, keyValue.Value);
			}
			return value;
		}

		private static Dictionary<long, int> Split(long value)
		{		
			Dictionary<long, int> dic = new Dictionary<long, int> ();	
			for (long i = 2; i * i <= value; 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