結果
問題 | No.811 約数の個数の最大化 |
ユーザー |
![]() |
提出日時 | 2019-04-12 21:41:51 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 152 ms / 2,000 ms |
コード長 | 1,921 bytes |
コンパイル時間 | 1,054 ms |
コンパイル使用メモリ | 116,388 KB |
実行使用メモリ | 23,424 KB |
最終ジャッジ日時 | 2024-09-14 17:50:50 |
合計ジャッジ時間 | 2,797 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System; using System.IO; using System.Linq; using System.Collections; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; using static System.Math; using Debug = System.Diagnostics.Debug; using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions; using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute; static class P { static void Main() { var nk = Console.ReadLine().Split().Select(int.Parse).ToArray(); var factorOfN = Factors(nk[0]).ToArray(); long max = 0; int maxI = 0; for (int i = 1; i < nk[0]; i++) { int counter = 0; int ptr = 0; var factors = Factors(i).ToArray(); foreach (var item in factors) { while (factorOfN[ptr] < item) { ptr++; if (ptr >= factorOfN.Length) goto end; } if (factorOfN[ptr] == item) { counter++; ptr++; if (ptr >= factorOfN.Length) goto end; } } end:; if (counter < nk[1]) continue; var v = factors.GroupBy(x => x).Aggregate(1L, (x, y) => x * (y.Count() + 1)); if (max < v) { maxI = i; max = v; } } Console.WriteLine(maxI); } static IEnumerable<long> Factors(long n) { while (n % 2 == 0) { n /= 2; yield return 2; } long i = 3; while (i * i <= n) { if (n % i == 0) { n /= i; yield return i; } else i += 2; } if (n != 1) yield return n; } }