結果

問題 No.368 LCM of K-products
ユーザー mbanmban
提出日時 2017-07-26 23:14:58
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,313 bytes
コンパイル時間 979 ms
コンパイル使用メモリ 114,848 KB
実行使用メモリ 46,108 KB
最終ジャッジ日時 2024-04-18 02:03:21
合計ジャッジ時間 6,304 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 168 ms
31,844 KB
testcase_01 AC 238 ms
45,972 KB
testcase_02 AC 238 ms
43,812 KB
testcase_03 AC 233 ms
43,924 KB
testcase_04 AC 243 ms
45,844 KB
testcase_05 AC 234 ms
46,108 KB
testcase_06 AC 26 ms
27,280 KB
testcase_07 AC 26 ms
25,376 KB
testcase_08 AC 25 ms
27,288 KB
testcase_09 AC 25 ms
25,260 KB
testcase_10 AC 25 ms
23,480 KB
testcase_11 AC 26 ms
27,156 KB
testcase_12 AC 26 ms
25,232 KB
testcase_13 AC 117 ms
27,732 KB
testcase_14 AC 177 ms
32,104 KB
testcase_15 AC 195 ms
27,692 KB
testcase_16 AC 173 ms
29,924 KB
testcase_17 AC 152 ms
27,868 KB
testcase_18 AC 199 ms
31,764 KB
testcase_19 AC 64 ms
29,900 KB
testcase_20 AC 143 ms
29,912 KB
testcase_21 AC 54 ms
27,988 KB
testcase_22 AC 188 ms
31,980 KB
testcase_23 AC 26 ms
27,400 KB
testcase_24 AC 26 ms
27,404 KB
testcase_25 AC 27 ms
25,492 KB
testcase_26 AC 28 ms
25,228 KB
testcase_27 AC 26 ms
25,492 KB
testcase_28 AC 27 ms
27,268 KB
testcase_29 AC 26 ms
25,236 KB
testcase_30 AC 27 ms
25,360 KB
testcase_31 AC 26 ms
27,400 KB
testcase_32 AC 25 ms
25,232 KB
testcase_33 WA -
testcase_34 AC 242 ms
45,836 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.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N, K;
    private long[] A;
    private long ans = 1;
    private long[] Primes;
    private const long Mod = (int)1e9 + 7;

    private void Scan()
    {
        var line = Console.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        K = int.Parse(line[1]);
        A = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

    private void PrimeCalc()
    {
        int max = 32000;
        bool[] b = new bool[max + 1];
        b[0] = b[1] = true;
        var list = new List<long>();
        int i;
        for (i = 2; i * i <= max; i++)
        {
            if (!b[i])
            {
                list.Add(i);
                for (int j = i + i; j <= max; j += i)
                {
                    b[j] = true;
                }
            }
        }
        for (; i <= max; i++)
        {
            if (!b[i])
            {
                list.Add(i);
            }
        }
        Primes = list.ToArray();
    }

    private long Pow(long a, long b)
    {
        long res = 1;
        while (b > 0)
        {
            if (b % 2 == 1)
            {
                res *= a;
                res %= Mod;
            }
            a *= a;
            a %= Mod;
            b /= 2;
        }
        return res;
    }

    private void C(long n)
    {
        long[] cnt = new long[N];
        for (int i = 0; i < N; i++)
        {
            while (A[i] % n == 0)
            {
                cnt[i]++;
                A[i] /= n;
            }
        }
        Array.Sort(cnt, (a, b) => -a.CompareTo(b));
        long sum = 0;
        for (int i = 0; i < K; i++)
        {
            sum += cnt[i];
        }
        ans *= Pow(n, sum);
        ans %= Mod;
    }

    public void Solve()
    {
        Scan();
        PrimeCalc();
        foreach (long i in Primes)
        {
            C(i);
        }
        foreach (long i in A)
        {
            ans *= i;
            ans %= Mod;
        }
        Console.WriteLine(ans);
    }
}
0