結果

問題 No.1731 Product of Subsequence
ユーザー umezo
提出日時 2021-11-07 19:47:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,410 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 213,164 KB
最終ジャッジ日時 2025-01-25 14:45:02
ジャッジサーバーID
(参考情報)
judge10 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;

#include<bits/stdc++.h>
using namespace std;

ll dp[2010][2010];
const int MOD=1e9+7;

vector<ll> divisor(ll x){
  set<ll> s;
  for(ll i=1;i*i<=x;i++){
    if(x%i==0){
      s.insert(i);
      s.insert(x/i);
    }
  }
  vector<ll> res;
  for(auto y:s) res.push_back(y);
  sort(ALL(res));
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  ll n,k;
  cin>>n>>k;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  
  vector<ll> D=divisor(k);
  int d=D.size();
  map<ll,ll> m;
  rep(i,d) m[D[i]]=i;
  
  dp[0][0]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<d;j++){
      ll tmp=D[j];
      dp[i][m[tmp]]=(dp[i][m[tmp]]+dp[i-1][m[tmp]])%MOD;
      ll b=gcd(A[i-1],k);
      ll c=k/b;
      ll a=gcd(c,tmp);
      dp[i][m[a*b]]=(dp[i][m[a*b]]+dp[i-1][m[tmp]])%MOD;
    }
  }
  if(k==1) cout<<dp[n][m[k]]-1<<endl;
  else cout<<dp[n][m[k]]<<endl;

  return 0;
}
0