結果
問題 | No.316 もっと刺激的なFizzBuzzをください |
ユーザー |
|
提出日時 | 2017-08-27 23:40:06 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 624 ms / 1,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 807 ms |
コンパイル使用メモリ | 112,152 KB |
実行使用メモリ | 315,652 KB |
最終ジャッジ日時 | 2024-11-06 07:04:08 |
合計ジャッジ時間 | 4,556 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.
ソースコード
using System;using System.Collections.Generic;using System.Linq;class Program {static void Main() {long n = long.Parse(Console.ReadLine());long[] abc = Console.ReadLine().Split().Select(long.Parse).ToArray();long lcm = Lcm(Lcm(abc[0], abc[1]), abc[2]);long ans = 0;if (lcm < n) {HashSet<int> hit = new HashSet<int>();foreach (int i in abc) {for (int j = i; j <= lcm; j += i) {hit.Add(j);}}ans += hit.Count * (n / lcm);}long m = n % lcm;HashSet<int> hit2 = new HashSet<int>();foreach (int i in abc) {for (int j = i; j <= m; j += i) {hit2.Add(j);}}ans += hit2.Count;Console.WriteLine(ans);}// 最小公倍数 出典: http://qiita.com/gushwell/items/f08d0e71fa0480dbb396public 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;}}