結果

問題 No.368 LCM of K-products
ユーザー 夜
提出日時 2021-02-23 21:40:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 335 ms / 2,000 ms
コード長 1,036 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 111,068 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 22:37:32
合計ジャッジ時間 5,424 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 169 ms
4,348 KB
testcase_01 AC 103 ms
4,348 KB
testcase_02 AC 247 ms
4,348 KB
testcase_03 AC 173 ms
4,348 KB
testcase_04 AC 157 ms
4,348 KB
testcase_05 AC 335 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 119 ms
4,348 KB
testcase_14 AC 181 ms
4,348 KB
testcase_15 AC 200 ms
4,348 KB
testcase_16 AC 174 ms
4,348 KB
testcase_17 AC 148 ms
4,348 KB
testcase_18 AC 206 ms
4,348 KB
testcase_19 AC 54 ms
4,348 KB
testcase_20 AC 140 ms
4,348 KB
testcase_21 AC 35 ms
4,348 KB
testcase_22 AC 200 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 80 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
map<long long, vector<int>> m;
long long a[1010];
long long mod = 1000000007;
set<long long> st;
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		long long a1 = a[i];
		for (long long j = 2; j * j <= a[i]; j++) {
			if (a1 % j == 0) {
				st.insert(j);
				int co = 0;
				while (a1 % j == 0) {
					a1 /= j;
					co++;
				}
				m[j].emplace_back(co);
			}
		}
		if (a1 != 1) {
			st.insert(a1);
			m[a1].emplace_back(1);
		}
	}
	long long ans = 1;
	for (auto i = st.begin(); i != st.end(); i++) {
		sort(m[*i].rbegin(), m[*i].rend());
		int n1 = m[*i].size();
		for (int j = 0; j < min(k, n1); j++) {
			for (int l = 0; l < m[*i][j]; l++) {
				ans *= *i;
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
}
0