結果
| 問題 |
No.316 もっと刺激的なFizzBuzzをください
|
| コンテスト | |
| ユーザー |
aketijyuuzou
|
| 提出日時 | 2024-10-13 07:47:06 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,659 bytes |
| コンパイル時間 | 1,150 ms |
| コンパイル使用メモリ | 112,148 KB |
| 実行使用メモリ | 29,224 KB |
| 最終ジャッジ日時 | 2024-10-13 07:47:10 |
| 合計ジャッジ時間 | 3,360 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 33 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("100");
WillReturn.Add("2 3 5");
//74
//1以上100以下の範囲内には,
//2または3または5の倍数となる数字の個数が合計で74個あります
}
else if (InputPattern == "Input2") {
WillReturn.Add("100");
WillReturn.Add("2 5 6");
//60
}
else if (InputPattern == "Input3") {
WillReturn.Add("346346");
WillReturn.Add("25 575 2525");
//13853
}
else if (InputPattern == "Input4") {
WillReturn.Add("83359640");
WillReturn.Add("3304 9805 9945");
//42104
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long N = long.Parse(InputList[0]);
long[] wkArr = InputList[1].Split(' ').Select(X => long.Parse(X)).ToArray();
long a = wkArr[0];
long b = wkArr[1];
long c = wkArr[2];
//包除原理 N(A∪B∪C)=N(A)+N(B)+N(C)-N(A∩B)-N(A∩C)-N(B∩C)+N(A∩B∩C)で解く
long LCMab = a * b / DeriveGCD(a, b);
long LCMac = a * c / DeriveGCD(a, c);
long LCMbc = b * c / DeriveGCD(b, c);
long LCMabc = LCMab * c / DeriveGCD(LCMab, c);
Console.WriteLine("{0}と{1}とのLCM={2}", a, b, LCMab);
Console.WriteLine("{0}と{1}とのLCM={2}", a, c, LCMac);
Console.WriteLine("{0}と{1}とのLCM={2}", b, c, LCMbc);
Console.WriteLine("{0}と{1}と{2}のLCM={3}", a,b, c, LCMabc);
long Na = N / a;
long Nb = N / b;
long Nc = N / c;
long Nab = N / LCMab;
long Nac = N / LCMac;
long Nbc = N / LCMbc;
long Nabc = N / LCMabc;
Console.WriteLine(Na + Nb + Nc - Nab - Nac - Nbc + Nabc);
}
//ユークリッドの互除法で2数の最大公約数を求める
static long DeriveGCD(long pVal1, long pVal2)
{
long WarareruKazu = pVal2;
long WaruKazu = pVal1;
while (true) {
long Amari = WarareruKazu % WaruKazu;
if (Amari == 0) return WaruKazu;
WarareruKazu = WaruKazu;
WaruKazu = Amari;
}
}
}
aketijyuuzou