結果

問題 No.368 LCM of K-products
ユーザー rickythetarickytheta
提出日時 2016-04-29 23:30:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,395 bytes
コンパイル時間 1,604 ms
コンパイル使用メモリ 170,960 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-23 21:10:56
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
4,348 KB
testcase_01 AC 50 ms
4,348 KB
testcase_02 AC 35 ms
4,348 KB
testcase_03 AC 39 ms
4,348 KB
testcase_04 AC 40 ms
4,348 KB
testcase_05 AC 35 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 3 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 20 ms
4,348 KB
testcase_14 AC 31 ms
4,348 KB
testcase_15 AC 35 ms
4,348 KB
testcase_16 AC 30 ms
4,348 KB
testcase_17 AC 26 ms
4,348 KB
testcase_18 AC 37 ms
4,348 KB
testcase_19 AC 10 ms
4,348 KB
testcase_20 AC 24 ms
4,348 KB
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 35 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
testcase_24 AC 3 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 2 ms
4,348 KB
testcase_29 AC 3 ms
4,348 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 3 ms
4,348 KB
testcase_32 AC 3 ms
4,348 KB
testcase_33 AC 15 ms
4,348 KB
testcase_34 AC 36 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]);
      |           ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#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;
}
0