結果
問題 |
No.368 LCM of K-products
|
ユーザー |
![]() |
提出日時 | 2016-04-29 23:30:20 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 50 ms / 2,000 ms |
コード長 | 1,395 bytes |
コンパイル時間 | 1,454 ms |
コンパイル使用メモリ | 169,716 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 14:43:27 |
合計ジャッジ時間 | 3,028 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:51:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | scanf("%d%d",&n,&k); | ~~~~~^~~~~~~~~~~~~~ main.cpp:52:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | REP(i,n)scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; typedef pair<int,int> pii; #define REP(i,n) for(ll i=0;i<n;++i) #define REPR(i,n) for(ll i=1;i<n;++i) #define FOR(i,a,b) for(ll i=a;i<b;++i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl #define ALL(a) (a).begin(),(a).end() #define MOD (ll)(1e9+7) #define ADD(a,b) a=((a)+(b))%MOD #define FIX(a) ((a)%MOD+MOD)%MOD int n,k; int a[1252]; int st[1252]; ll mdpw(ll a,ll b){ ll r = 1; while(b){ if(b&1)r=r*a%MOD; a=a*a%MOD; b>>=1; } return r; } void check(ll &ans, int p){ bool ex = false; REP(i,n){ st[i] = 0; ex |= a[i]%p==0; while(a[i]%p==0)a[i]/=p,st[i]++; } if(!ex)return; sort(st,st+n,greater<int>()); int cnt = 0; REP(i,k)cnt += st[i]; ans = ans * mdpw(p,cnt) % MOD; } int main(){ scanf("%d%d",&n,&k); REP(i,n)scanf("%d",&a[i]); // sieve vector<bool> sv(100000,true); sv[0]=false; sv[1]=false; ll ans = 1; FOR(p,2,100000){ if(!sv[p])continue; check(ans,p); int it = 2*p; while(it<100000)sv[it]=false,it+=p; } map<int,int> M; REP(i,n)if(a[i]>1)M[a[i]]++; for(pii P: M){ int cnt = min(P.second,k); ans = ans * mdpw(P.first,cnt) % MOD; } printf("%lld\n",ans); return 0; }