結果
問題 |
No.368 LCM of K-products
|
ユーザー |
|
提出日時 | 2020-02-22 07:48:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 369 ms / 2,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 75,880 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-09 15:54:35 |
合計ジャッジ時間 | 7,055 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 8 | main() | ^~~~
ソースコード
#include<iostream> #include<vector> #include<algorithm> using namespace std; int N,K,A[1000]; long mod=1e9+7,ans=1; long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;} main() { cin>>N>>K; for(int i=0;i<N;i++)cin>>A[i]; for(int i=2;i*i<=1000000000;i++) { vector<int>cnt(N); for(int j=0;j<N;j++) { while(A[j]%i==0) { A[j]/=i; cnt[j]++; } } sort(cnt.begin(),cnt.end()); int x=0; for(int j=0;j<K;j++)x+=cnt[N-j-1]; ans=ans*power(i,x)%mod; } for(int i=0;i<N;i++) { if(A[i]==1)continue; int a=A[i]; int x=0; for(int j=0;j<N;j++) { if(A[j]==a) { A[j]=1; x++; } } ans=ans*power(a,x<K?x:K)%mod; } cout<<ans<<endl; }