結果
| 問題 | No.1731 Product of Subsequence | 
| コンテスト | |
| ユーザー |  srjywrdnprkt | 
| 提出日時 | 2023-01-16 15:07:18 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 923 ms / 2,000 ms | 
| コード長 | 779 bytes | 
| コンパイル時間 | 1,238 ms | 
| コンパイル使用メモリ | 117,896 KB | 
| 最終ジャッジ日時 | 2025-02-10 03:43:23 | 
| ジャッジサーバーID (参考情報) | judge4 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
ソースコード
#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;
}
            
            
            
        