結果
問題 | No.1731 Product of Subsequence |
ユーザー |
|
提出日時 | 2021-11-10 22:12:59 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 605 ms / 2,000 ms |
コード長 | 726 bytes |
コンパイル時間 | 5,573 ms |
コンパイル使用メモリ | 316,776 KB |
実行使用メモリ | 122,752 KB |
最終ジャッジ日時 | 2024-11-08 05:10:15 |
合計ジャッジ時間 | 12,067 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 31 |
ソースコード
#include <bits/stdc++.h>#if __has_include(<atcoder/all>)#include <atcoder/all>using namespace atcoder;#endif#define rep(i, n) for (int i = 0; i < (n); ++i)using std::cin;using std::cout;using std::gcd;using std::unordered_map;using std::vector;using ll = long long;using mint = modint1000000007;int main() {int n, k;cin >> n >> k;vector<ll> a(n);rep(i, n) cin >> a[i];rep(i, n) a[i] = gcd(a[i], k);vector<unordered_map<int, mint>> dp(n+1);dp[0][1] = 1;rep(i, n) {for (auto [j, x] : dp[i]) {// 不取 a[i]dp[i+1][j] += x;// 取 a[i]ll g = gcd(j*a[i], k);dp[i+1][g] += x;}}mint ans = dp[n][k];if (k == 1) ans -= 1;cout << ans.val() << '\n';return 0;}