結果
問題 | No.368 LCM of K-products |
ユーザー |
|
提出日時 | 2021-02-23 21:40:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 335 ms / 2,000 ms |
コード長 | 1,036 bytes |
コンパイル時間 | 1,235 ms |
コンパイル使用メモリ | 111,804 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 15:55:22 |
合計ジャッジ時間 | 5,280 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#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; }