結果

問題 No.811 約数の個数の最大化
ユーザー keymoonkeymoon
提出日時 2019-04-12 21:41:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 1,921 bytes
コンパイル時間 3,294 ms
コンパイル使用メモリ 108,696 KB
実行使用メモリ 30,024 KB
最終ジャッジ日時 2023-10-12 19:27:24
合計ジャッジ時間 5,837 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
23,800 KB
testcase_01 AC 68 ms
23,824 KB
testcase_02 AC 150 ms
23,868 KB
testcase_03 AC 67 ms
21,884 KB
testcase_04 AC 68 ms
21,780 KB
testcase_05 AC 69 ms
23,728 KB
testcase_06 AC 73 ms
23,880 KB
testcase_07 AC 77 ms
23,924 KB
testcase_08 AC 107 ms
25,884 KB
testcase_09 AC 114 ms
26,124 KB
testcase_10 AC 95 ms
26,096 KB
testcase_11 AC 147 ms
25,904 KB
testcase_12 AC 89 ms
27,996 KB
testcase_13 AC 184 ms
27,880 KB
testcase_14 AC 160 ms
30,024 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.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;
    }
}
0