結果

問題 No.1731 Product of Subsequence
ユーザー Lê Hoàng NgôLê Hoàng Ngô
提出日時 2024-06-28 23:55:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,876 bytes
コンパイル時間 2,241 ms
コンパイル使用メモリ 181,200 KB
実行使用メモリ 168,960 KB
最終ジャッジ日時 2024-06-28 23:55:37
合計ジャッジ時間 16,104 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rep_r(i,a,b) for(int i=a;i>=b;i--)
#define each(a,x) for (auto& x : a)
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define sz(x) int(x.size())
#define so(x) sort(all(x))
#define so_r(x) sort(all(x),greater<int>())
#define lb lower_bound
#define ub upper_bound
const char nl = '\n';
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int bit_cnt(int x){
    return __builtin_popcount(x);
}
ll bex(ll a, ll b, ll mod = 1e9 + 7){ll res = 1LL; while(b){ if (b&1) res = res * a % mod; a = a * a % mod; b >>= 1;} return res;}
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b;return true;}else return false;}
template<class t,class u> bool chmin(t&a,u b){if(b<a){a=b;return true;}else return false;}

const int MOD = 1e9+7;
const int N = 5e5 + 5;
const ll INF = 1e16;
int n,k;
ll a[2005];
vector<int> fac(int x) { 
    vector<int> f;
    for (int i = 1; 1LL * i * i <= n; i++){ 
        if (x % i == 0) {
            f.push_back(i); 
            if (x / i != i) f.push_back(x/i);
        }
    }
    sort(all(f));
    return f;
}
map<ll,ll> dp[2005]; 
void solve(){
    cin >> n >> k;
    rep(i,1,n) cin >> a[i]; 
    dp[0][1] = 1; 
    rep(i,1,n){
        ll G = __gcd(a[i], 1LL * k);
        each(dp[i-1],p){
            ll uoc = p.first;
            ll g = __gcd(G * uoc, 1LL * k);
            // choose a[i]
            dp[i][g] += dp[i-1][uoc]; 
            dp[i][g] %= MOD;

            // not choose a[i]
            dp[i][uoc] += dp[i-1][uoc];
            dp[i][uoc] %= MOD;
        }
    }
    cout << dp[n][k] << nl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1; 
    // cin >> t;

    while (t--){
        solve();
    }
}
0