結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
4,372 KB
testcase_01 AC 48 ms
4,372 KB
testcase_02 AC 35 ms
4,372 KB
testcase_03 AC 38 ms
4,372 KB
testcase_04 AC 40 ms
4,372 KB
testcase_05 AC 35 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 2 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,372 KB
testcase_10 AC 3 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 3 ms
4,372 KB
testcase_13 AC 21 ms
4,372 KB
testcase_14 AC 32 ms
4,372 KB
testcase_15 AC 35 ms
4,372 KB
testcase_16 AC 31 ms
4,372 KB
testcase_17 AC 26 ms
4,372 KB
testcase_18 AC 36 ms
4,372 KB
testcase_19 AC 10 ms
4,372 KB
testcase_20 AC 24 ms
4,372 KB
testcase_21 AC 8 ms
4,372 KB
testcase_22 AC 35 ms
4,372 KB
testcase_23 AC 2 ms
4,372 KB
testcase_24 AC 3 ms
4,372 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 3 ms
4,372 KB
testcase_27 AC 3 ms
4,372 KB
testcase_28 AC 3 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
testcase_30 AC 2 ms
4,372 KB
testcase_31 AC 3 ms
4,372 KB
testcase_32 AC 3 ms
4,372 KB
testcase_33 AC 15 ms
4,372 KB
testcase_34 AC 36 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:72:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   72 |   scanf("%d%d",&n,&k);
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:73:16: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |   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];

// montgomery multiplication
// mod N
// R = 1<<30
// M(x) = xR = MR(xR2)
// MR(x) = xR^-1

ll R = 1<<30;
ll Rmask = R-1;
int Rshift = 30;
ll Rinv = 73699066ll;
ll N = MOD;
ll Ninv = 79133769ll;
ll R2 = 536396504ll;
ll M1 = 73741817ll;

ll MR(ll x){
  ll t = (x+((x*Ninv)&Rmask)*N)>>Rshift;
  return (t>=N?t-N:t);
}

ll mdpw(ll a,ll b){
  a = MR(a*R2);
  ll r = M1;
  while(b){
    if(b&1)r=MR(r*a);
    a=MR(a*a);
    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=MR(ans*mdpw(p,cnt));
}

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 = M1;
  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=MR(ans*mdpw(P.first,cnt));
  }
  printf("%lld\n",MR(ans));
  return 0;
}
0