結果
| 問題 |
No.1731 Product of Subsequence
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-26 16:02:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 344 ms / 2,000 ms |
| コード長 | 1,151 bytes |
| コンパイル時間 | 4,300 ms |
| コンパイル使用メモリ | 261,664 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2025-03-26 16:02:53 |
| 合計ジャッジ時間 | 8,006 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 31 |
ソースコード
#include <bits/extc++.h>
using i64 = long long;
constexpr int P = 1E9 + 7;
inline void Inc(int &x, int y) {
if ((x += y) >= P) x -= P;
}
int main() {
std::cin.tie(nullptr) -> sync_with_stdio(false);
int n;
i64 m;
std::cin >> n >> m;
std::vector<i64> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
a[i] = std::__gcd(a[i], m);
}
auto lcm = [&](int x, int y) {
return 1ll * x * y / std::__gcd(x, y);
};
int cnt = 0;
__gnu_pbds::gp_hash_table<i64, int> mp;
std::vector<i64> d;
for (int i = 1; i * i <= m; i++) {
if (m % i == 0) {
d.push_back(i);
if (i != m / i) d.push_back(m / i);
}
}
std::sort(d.begin(), d.end());
for (auto x : d) {
mp[x] = cnt++;
}
std::vector<int> f(cnt);
f[0] = 1;
for (int i = 0; i < n; i++) {
std::vector<int> nf(cnt);
for (auto x : d) {
Inc(nf[mp[std::__gcd(1ll * m, 1ll * x * a[i])]], f[mp[x]]);
Inc(nf[mp[x]], f[mp[x]]);
}
f = nf;
}
std::cout << f[cnt - 1] - (m == 1);
return 0;
}
lam6er