結果
問題 |
No.368 LCM of K-products
|
ユーザー |
![]() |
提出日時 | 2016-04-30 01:27:08 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 109 ms / 2,000 ms |
コード長 | 1,301 bytes |
コンパイル時間 | 768 ms |
コンパイル使用メモリ | 81,956 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 14:44:25 |
合計ジャッジ時間 | 1,950 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; #define RREP(i,s,e) for (i = s; i >= e; i--) #define rrep(i,n) RREP(i,n-1,0) #define REP(i,s,e) for (i = s; i < e; i++) #define rep(i,n) REP(i,0,n) #define INF 100000000 #define MOD 1000000007 typedef long long ll; ll power(ll x, int n) { ll ret = 1; while (n > 0) { if (n % 2) { ret *= x; ret %= MOD; } x *= x; x %= MOD; n /= 2; } return ret; } void get_factors(int n, map<int,int>& m) { int i; i = 2; while (i*i <= n) { if (n % i == 0) { m[i]++; n /= i; } else i++; } m[n]++; } int main() { int i, j, n, k; ll ans; map<int,vector<int>> factors; cin >> n >> k; rep (i,n) { int a; map<int,int> m; cin >> a; get_factors(a,m); for (auto&& p : m) factors[p.first].push_back(p.second); } ans = 1; for (auto&& m : factors) { int sum = 0; sort(m.second.begin(),m.second.end(),greater<int>{}); rep (i,min(k,(int)m.second.size())) sum += m.second[i]; ans *= power(m.first,sum); ans %= MOD; } cout << ans << endl; return 0; }