結果

問題 No.368 LCM of K-products
ユーザー mbanmban
提出日時 2017-06-02 14:31:15
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,432 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 111,640 KB
実行使用メモリ 28,784 KB
最終ジャッジ日時 2023-10-21 20:46:29
合計ジャッジ時間 11,744 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
28,712 KB
testcase_01 AC 563 ms
28,736 KB
testcase_02 AC 567 ms
28,736 KB
testcase_03 AC 565 ms
28,736 KB
testcase_04 AC 566 ms
28,736 KB
testcase_05 AC 563 ms
28,736 KB
testcase_06 AC 29 ms
24,232 KB
testcase_07 AC 29 ms
24,236 KB
testcase_08 AC 30 ms
24,236 KB
testcase_09 AC 30 ms
24,236 KB
testcase_10 AC 31 ms
24,244 KB
testcase_11 AC 30 ms
24,236 KB
testcase_12 AC 31 ms
24,244 KB
testcase_13 AC 272 ms
28,712 KB
testcase_14 AC 450 ms
28,712 KB
testcase_15 AC 506 ms
28,712 KB
testcase_16 AC 441 ms
28,712 KB
testcase_17 AC 373 ms
28,724 KB
testcase_18 AC 507 ms
28,712 KB
testcase_19 AC 129 ms
28,700 KB
testcase_20 AC 351 ms
28,724 KB
testcase_21 AC 95 ms
28,712 KB
testcase_22 AC 492 ms
28,712 KB
testcase_23 AC 29 ms
24,236 KB
testcase_24 AC 30 ms
24,236 KB
testcase_25 AC 30 ms
24,244 KB
testcase_26 AC 29 ms
24,236 KB
testcase_27 AC 31 ms
24,244 KB
testcase_28 AC 30 ms
24,236 KB
testcase_29 AC 31 ms
24,244 KB
testcase_30 AC 31 ms
24,244 KB
testcase_31 AC 30 ms
24,244 KB
testcase_32 AC 30 ms
24,244 KB
testcase_33 WA -
testcase_34 AC 553 ms
28,736 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;

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

struct P
{
    public int Cost, Index;
    public P(int cost, int index)
    {
        Cost = cost;
        Index = index;
    }
}

class Magatro
{
    private int N, K;
    private int[] A;
    private List<int> Primes = new List<int>();
    private long ans = 1;
    private const int Mod = 1000000007;

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

    private void P()
    {
        int max = 100000;
        bool[] b = new bool[max + 1];
        b[0] = true;
        b[1] = true;
        for (int i = 2; i * i <= max; i++)
        {
            if (!b[i])
            {
                for (int j = i + i; j <= max; j += i)
                {
                    b[j] = true;
                }
            }
        }
        for (int i = 0; i <= max; i++)
        {
            if (!b[i])
            {
                Primes.Add(i);
            }
        }
    }

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

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

    public void Solve()
    {
        Scan();
        P();
        foreach (int i in Primes)
        {
            Calc(i);
        }
        foreach (int i in A)
        {
            ans *= i;
            ans %= Mod;
        }
        Console.WriteLine(ans);
    }
}
0