結果

問題 No.368 LCM of K-products
ユーザー mbanmban
提出日時 2017-07-27 00:30:53
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,458 bytes
コンパイル時間 1,160 ms
コンパイル使用メモリ 107,520 KB
実行使用メモリ 35,016 KB
最終ジャッジ日時 2024-04-18 02:07:57
合計ジャッジ時間 12,075 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 469 ms
22,408 KB
testcase_01 AC 699 ms
35,004 KB
testcase_02 AC 696 ms
35,000 KB
testcase_03 AC 694 ms
35,016 KB
testcase_04 AC 694 ms
34,876 KB
testcase_05 AC 664 ms
35,004 KB
testcase_06 AC 29 ms
18,276 KB
testcase_07 AC 31 ms
18,356 KB
testcase_08 AC 31 ms
18,300 KB
testcase_09 AC 29 ms
18,572 KB
testcase_10 AC 31 ms
18,656 KB
testcase_11 AC 31 ms
18,440 KB
testcase_12 AC 31 ms
18,972 KB
testcase_13 AC 290 ms
22,532 KB
testcase_14 AC 493 ms
22,668 KB
testcase_15 AC 554 ms
22,528 KB
testcase_16 AC 500 ms
22,660 KB
testcase_17 AC 419 ms
22,528 KB
testcase_18 AC 570 ms
22,548 KB
testcase_19 AC 147 ms
22,264 KB
testcase_20 AC 390 ms
22,540 KB
testcase_21 AC 107 ms
22,552 KB
testcase_22 AC 562 ms
22,672 KB
testcase_23 AC 31 ms
18,368 KB
testcase_24 AC 29 ms
18,352 KB
testcase_25 AC 32 ms
18,748 KB
testcase_26 AC 30 ms
18,240 KB
testcase_27 AC 32 ms
19,028 KB
testcase_28 AC 31 ms
18,180 KB
testcase_29 AC 32 ms
18,820 KB
testcase_30 AC 32 ms
18,972 KB
testcase_31 AC 32 ms
19,108 KB
testcase_32 AC 33 ms
19,016 KB
testcase_33 WA -
testcase_34 AC 684 ms
34,872 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;
    StreamReader sr;

    private void Scan()
    {
        sr = new StreamReader(Console.OpenStandardInput());
      
        var line = sr.ReadLine().Split(' ');
        N = int.Parse(line[0]);
        K = int.Parse(line[1]);
        A = new long[N];
        line = sr.ReadLine().Split(' ');
        for (int i = 0; i < N; i++)
        {
            A[i] = int.Parse(line[i]);
        }
    }

    private void PrimeCalc()
    {
        int max = 100000;
        bool[] b = new bool[max + 1];
        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