結果
問題 | No.368 LCM of K-products |
ユーザー |
![]() |
提出日時 | 2016-04-29 22:45:47 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 132 ms / 2,000 ms |
コード長 | 1,487 bytes |
コンパイル時間 | 757 ms |
コンパイル使用メモリ | 89,100 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 14:41:46 |
合計ジャッジ時間 | 2,116 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#define _USE_MATH_DEFINES#include <algorithm>#include <cstdio>#include <functional>#include <iostream>#include <cfloat>#include <climits>#include <cstdlib>#include <cstring>#include <cmath>#include <map>#include <queue>#include <set>#include <sstream>#include <stack>#include <string>#include <time.h>#include <vector>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> i_i;typedef pair<ll, int> ll_i;typedef pair<double, int> d_i;typedef pair<ll, ll> ll_ll;typedef pair<double, double> d_d;struct edge { int u, v; ll w; };ll MOD = 1000000007;ll _MOD = 1000000009;double EPS = 1e-10;int pow_mod(ll x, ll n, int M) {ll ans = 1;for (; n; n>>=1) {if (n & 1) ans = ans * x % M;x = x * x % M;}return ans;}int main() {int N, K; cin >> N >> K;vector<int> a(N);for (int i = 0; i < N; i++)cin >> a[i];vector<int> ps;for (int x: a) {for (int p = 2; p * p <= x; p++)if (x % p == 0) {ps.push_back(p);for (; x % p == 0; x /= p);}if (x > 1) ps.push_back(x);}sort(ps.begin(), ps.end());ps.erase(unique(ps.begin(), ps.end()), ps.end());int ans = 1;for (int p: ps) {vector<int> b(N);for (int i = 0; i < N; i++)for (int x = a[i]; x % p == 0; x /= p)b[i]++;sort(b.begin(), b.end());reverse(b.begin(), b.end());int sum = 0;for (int i = 0; i < K; i++)sum += b[i];ans = (ll)ans * pow_mod(p, sum, MOD) % MOD;}cout << ans << endl;}