結果

問題 No.1731 Product of Subsequence
ユーザー 👑 kakel-sankakel-san
提出日時 2021-11-05 22:30:05
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 414 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 114,200 KB
実行使用メモリ 52,628 KB
最終ジャッジ日時 2024-04-25 17:29:30
合計ジャッジ時間 6,941 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 301 ms
44,884 KB
testcase_01 AC 29 ms
27,560 KB
testcase_02 AC 31 ms
25,508 KB
testcase_03 AC 30 ms
25,772 KB
testcase_04 AC 30 ms
25,568 KB
testcase_05 AC 30 ms
25,444 KB
testcase_06 AC 31 ms
25,264 KB
testcase_07 AC 31 ms
25,208 KB
testcase_08 AC 44 ms
25,948 KB
testcase_09 AC 36 ms
25,952 KB
testcase_10 AC 299 ms
46,040 KB
testcase_11 AC 259 ms
48,928 KB
testcase_12 AC 35 ms
26,036 KB
testcase_13 AC 40 ms
27,976 KB
testcase_14 AC 245 ms
49,764 KB
testcase_15 AC 31 ms
25,180 KB
testcase_16 AC 30 ms
25,444 KB
testcase_17 AC 32 ms
27,436 KB
testcase_18 AC 414 ms
45,900 KB
testcase_19 AC 42 ms
26,076 KB
testcase_20 AC 327 ms
52,628 KB
testcase_21 AC 292 ms
48,204 KB
testcase_22 AC 199 ms
48,212 KB
testcase_23 AC 36 ms
24,240 KB
testcase_24 AC 44 ms
25,988 KB
testcase_25 AC 39 ms
25,828 KB
testcase_26 AC 77 ms
26,304 KB
testcase_27 AC 98 ms
30,084 KB
testcase_28 AC 161 ms
29,952 KB
testcase_29 AC 82 ms
32,140 KB
testcase_30 AC 250 ms
47,952 KB
testcase_31 AC 191 ms
45,904 KB
testcase_32 AC 34 ms
25,772 KB
testcase_33 AC 47 ms
26,208 KB
testcase_34 AC 51 ms
25,696 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.Generic;
using static System.Console;
using System.Linq;

class yuki321
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, k) = ((int)c[0], c[1]);
        var a = NList;

        var gcda = new long[n];
        for (var i = 0; i < n; ++i) gcda[i] = GCD(k, a[i]);

        var key = 1000000007;
        var divs = Divs(k);
        var dic = new Dictionary<long, int>();
        for (var i = 0; i < divs.Count; ++i) dic[divs[i]] = i;
        var dp = new long[divs.Count];
        dp[0] = 1;
        for (var i = 0; i < n; ++i)
        {
            var next = (long[]) dp.Clone();
            for (var j = 0; j < dp.Length; ++j)
            {
                var nj = dic[GCD(gcda[i] * divs[j], k)];
                next[nj] = (next[nj] + dp[j]) % key;
            }
            dp = next;
        }
        dp[0] = (dp[0] + key - 1) % key;
        WriteLine(dp.Last());
    }
    static long GCD(long a, long b)
    {
        if (a < b) return GCD(b, a);
        if (a % b == 0) return b;
        return GCD(b, a % b);
    }
    static List<long> Divs(long a)
    {
        var list = new List<long>();
        var rev = new List<long>();
        for (var i = 1; i * i <= a; ++i)
        {
            if (a % i == 0)
            {
                list.Add(i);
                if (i * i < a) rev.Add(a / i);
            }
        }
        rev.Reverse();
        list.AddRange(rev);
        return list;
    }
}
0