結果

問題 No.1731 Product of Subsequence
ユーザー V_MelvilleV_Melville
提出日時 2021-11-06 21:22:01
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 950 bytes
コンパイル時間 5,246 ms
コンパイル使用メモリ 320,136 KB
実行使用メモリ 14,036 KB
最終ジャッジ日時 2023-08-07 23:31:02
合計ジャッジ時間 9,478 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 234 ms
13,336 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 17 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 296 ms
13,652 KB
testcase_11 AC 253 ms
12,628 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 6 ms
4,380 KB
testcase_14 AC 233 ms
11,276 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 331 ms
13,976 KB
testcase_19 AC 5 ms
4,376 KB
testcase_20 AC 271 ms
11,928 KB
testcase_21 AC 297 ms
13,952 KB
testcase_22 AC 102 ms
13,596 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 43 ms
5,456 KB
testcase_27 AC 62 ms
6,020 KB
testcase_28 AC 139 ms
8,556 KB
testcase_29 AC 46 ms
5,520 KB
testcase_30 AC 203 ms
14,036 KB
testcase_31 AC 102 ms
13,592 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 9 ms
4,396 KB
testcase_34 AC 12 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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::map;
using std::vector;
using ll = long long;
using mint = modint1000000007;

inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

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<ll> f;
	for(ll i = 1; i*i <= k; ++i) {
		if (k % i == 0) {
			f.push_back(i);
			if (k/i != i) f.push_back(k/i);
		}
	}
	sort(f.begin(), f.end());
	int m = f.size();
	map<ll, int> mp;
	rep(i, m) mp[f[i]] = i;
	
	vector dp(n+1, vector<mint>(m));
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, m) {
			dp[i+1][j] += dp[i][j];
			
			ll g = gcd(f[j]*a[i], k);
			dp[i+1][mp[g]] += dp[i][j];
		}
	}
	
	mint ans = dp[n][m-1];
	if (k == 1) ans -= 1;
	cout << ans.val() << '\n';
	
	return 0;
}
0