結果

問題 No.368 LCM of K-products
ユーザー YazatenYazaten
提出日時 2016-04-30 09:46:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,053 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 183,864 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:12:22
合計ジャッジ時間 3,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,348 KB
testcase_01 AC 42 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 14 ms
4,348 KB
testcase_04 AC 6 ms
4,348 KB
testcase_05 AC 145 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 10 ms
4,348 KB
testcase_14 AC 16 ms
4,348 KB
testcase_15 AC 18 ms
4,348 KB
testcase_16 AC 14 ms
4,348 KB
testcase_17 AC 13 ms
4,348 KB
testcase_18 AC 18 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 13 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 18 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 8 ms
4,348 KB
testcase_34 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

ll power(ll a,ll b/*,ll mod*/){
	ll ret=1;
	if(b>0){
		ret = power(a,b/2/*,mod*/);
		if(b%2==0)ret = (ret*ret)/*%mod*/;
		else ret = (((ret*ret)/*%mod*/)*a)/*%mod*/;
	}
	return ret;
}

map<int,int> prime_factorization(int n){
	map<int,int> ret;
	
	for(int div=2;div<=1+sqrt(n);div++){
		while(n%div==0){
			ret[div]++;
			n/=div;
		}
	}
	if(n!=1)ret[n]++;
	return ret;
}

int main(){
	map<int,vector<int>> mp;
	
	int n,k;
	cin>>n>>k;
	rep(i,n){
		int a;
		cin>>a;
		map<int,int> res = prime_factorization(a);
		for(auto &p : res){
			mp[p.first].pb(p.second);
		}
	}
	
	ll ans = 1;
	for(auto &elm : mp){
		sort(all(elm.second),greater<int>());
		rep(i,min<ll>(k,elm.second.size())){
			ans = (ans*power(elm.first,elm.second[i]))%1000000007;
		}
	}
	cout<<ans<<endl;
}
0