結果
| 問題 |
No.1731 Product of Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-05 22:45:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,777 ms / 2,000 ms |
| コード長 | 949 bytes |
| コンパイル時間 | 1,914 ms |
| コンパイル使用メモリ | 180,212 KB |
| 実行使用メモリ | 169,216 KB |
| 最終ジャッジ日時 | 2024-11-08 04:49:28 |
| 合計ジャッジ時間 | 17,366 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = (l); i < (r); i++)
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int main() {
int N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, 0, N) cin >> A[i];
vector<map<ll, ll>> dp(N + 1);
dp[0][1] = 1;
ll MOD = 1000000007;
rep(i, 0, N) {
for (auto j : dp[i]) {
dp[i + 1][j.first] = (dp[i + 1][j.first] + j.second) % MOD;
ll x = gcd(j.first * gcd(A[i], K), K);
dp[i + 1][x] = (dp[i + 1][x] + j.second) % MOD;
}
}
ll ans = 0;
for (auto i : dp[N]) {
if (i.first % K == 0) ans = (ans + i.second) % MOD;
}
if (K == 1) ans--;
cout << ans << endl;
/*
rep(i, 0, N + 1) {
for (auto j : dp[i]) {
cout << "(" << j.first << "," << j.second << ")";
}
cout << endl;
}
*/
}