結果
問題 | No.368 LCM of K-products |
ユーザー |
![]() |
提出日時 | 2016-04-29 23:18:03 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 360 ms / 2,000 ms |
コード長 | 2,291 bytes |
コンパイル時間 | 1,589 ms |
コンパイル使用メモリ | 178,784 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 14:43:05 |
合計ジャッジ時間 | 5,786 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;typedef pair<ll, ll> P;#define EACH(i,a) for (auto& i : a)#define FOR(i,a,b) for (ll i=(a);i<(b);i++)#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)#define REP(i,n) for (ll i=0;i<(n);i++)#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)#define debug(x) cout<<#x<<": "<<x<<endl#define pb push_back#define ALL(a) (a).begin(),(a).end()const ll linf = 1e18;const int inf = 1e9;const double eps = 1e-12;const double pi = acos(-1);template<typename T>istream& operator>>(istream& is, vector<T>& vec) {EACH(x,vec) is >> x;return is;}/*template<class... T>ostream& operator<<(ostream& os, tuple<T...>& t) {for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {if (i) os << " ";os << get<0>(t);}return os;}*/template<typename T>ostream& operator<<(ostream& os, vector<T>& vec) {REP(i,vec.size()) {if (i) os << " ";os << vec[i];}return os;}template<typename T>ostream& operator<<(ostream& os, vector< vector<T> >& vec) {REP(i,vec.size()) {if (i) os << endl;os << vec[i];}return os;}map<ll, int> pf(ll n) {set<ll> s;for (ll i = 1; i*i <= n; ++i) {if (n % i == 0) {s.insert(i);s.insert(n/i);}}map<ll, int> res;EACH(i, s) {if (i == 1) continue;int cnt = 0;while (n % i == 0) {n /= i;++cnt;}if (cnt > 0) {res[i] = cnt;}}return res;}const ll mod = 1e9+7;ll add(ll a, ll b) {return (a + b) % mod;}ll mul(ll a, ll b) {return a * b % mod;}ll power(ll x, ll n) {ll res = 1;for (ll i = 1; i <= n; i <<= 1) {if (i & n) res = mul(res, x);x = mul(x, x);}return res;}int main() {std::ios::sync_with_stdio(false);std::cin.tie(0);int N, K; cin >> N >> K;vector<ll> a(N); cin >> a;vector< map<ll, int> > v(N);set<ll> s;REP(i, N) {v[i] = pf(a[i]);EACH(p, v[i]) {s.insert(p.first);}}map<ll, int> am;EACH(i, s) {vector<ll> a(N);REP(j, N) {if ( v[j].count(i) > 0 ) {a[j] = v[j][i];}}sort(ALL(a), greater<ll>());int sum = 0;REP(j, K) {sum += a[j];}am[i] = sum;}ll ans = 1;EACH(p, am) {ans = mul(ans, power(p.first, p.second));}cout << ans << endl;}