結果
| 問題 | No.1731 Product of Subsequence | 
| コンテスト | |
| ユーザー |  nonon | 
| 提出日時 | 2024-09-30 18:58:55 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 493 ms / 2,000 ms | 
| コード長 | 690 bytes | 
| コンパイル時間 | 2,843 ms | 
| コンパイル使用メモリ | 256,812 KB | 
| 実行使用メモリ | 6,820 KB | 
| 最終ジャッジ日時 | 2024-09-30 18:59:05 | 
| 合計ジャッジ時間 | 7,656 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
ソースコード
#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::modint1000000007;
long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    long long K;
    cin >> N >> K;
    map<long long, mint> dp;
    bool fn = false;
    dp[1] = 1;
    while (N--) {
        auto ep = dp;
        long long A;
        cin >> A;
        if (A % K != 0) fn = true;
        A = gcd(A, K);
        for (auto [key, val] : dp) {
            ep[gcd(key * A, K)] += val;
        }
        dp = ep;
    }
    if (!fn && K == 1) dp[K]--;
    cout << dp[K].val() << endl;
}
            
            
            
        