結果
問題 | No.368 LCM of K-products |
ユーザー | saltcandy123 |
提出日時 | 2016-04-29 23:53:00 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 379 ms / 2,000 ms |
コード長 | 1,313 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 77,400 KB |
実行使用メモリ | 11,776 KB |
最終ジャッジ日時 | 2024-09-22 14:44:30 |
合計ジャッジ時間 | 2,795 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <algorithm> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; vector<int> compute_primes(int n, long long a[]) { set<int> s; for (int ni = 0; ni < n; ++ni) { long long x = a[ni]; for (int p = 2; p * p <= x; ++p) { if (x % p == 0) { s.insert(p); while (x % p == 0) { x /= p; } } } if (x > 1) { s.insert(x); } } return vector<int>(s.begin(), s.end()); } int main() { int n, k; long long a[1000]; vector<int> primes; vector<vector<int>> factors; long long r = 1; cin >> n >> k; for (int ni = 0; ni < n; ++ni) { cin >> a[ni]; } primes = compute_primes(n, a); factors.resize(primes.size()); for (int ni = 0; ni < n; ++ni) { long long x = a[ni]; for (size_t i = 0; i < primes.size(); ++i) { factors[i].push_back(0); while (x % primes[i] == 0) { ++factors[i].back(); x /= primes[i]; } } } for (size_t i = 0; i < primes.size(); ++i) { sort(factors[i].begin(), factors[i].end()); for (int j = 0; j < min(k, int(factors[i].size())); ++j) { for (int x = 0; x < factors[i][factors[i].size() - 1 - j]; ++x) { r = r * primes[i] % 1000000007; } } } cout << r << endl; return 0; }