結果

問題 No.1731 Product of Subsequence
ユーザー srjywrdnprkt
提出日時 2023-01-16 15:06:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 913 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 115,816 KB
最終ジャッジ日時 2025-02-10 03:43:09
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

const long long modc = 1e9+7;

int main(){

    long long N, K, X, g;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i=0; i<N; i++) cin >> A[i];

    vector<map<long long, long long>> dp(N+1);
    dp[0][1] = 1;

    for (int i=1; i<=N; i++){
        X = gcd(K, A[i-1]);
        for (auto [a, b] : dp[i-1]){
            dp[i][a] += b;
            dp[i][a] %= modc;

            g = gcd(X*a, K);
            dp[i][g] += b;
            dp[i][g] %= modc;
        }
    }

    cout << dp[N][K] - (K == 1) << endl;

    return 0;
}
0