結果
問題 |
No.368 LCM of K-products
|
ユーザー |
![]() |
提出日時 | 2016-04-29 23:56:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 48 ms / 2,000 ms |
コード長 | 1,722 bytes |
コンパイル時間 | 1,527 ms |
コンパイル使用メモリ | 169,892 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-22 14:43:56 |
合計ジャッジ時間 | 2,917 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
コンパイルメッセージ
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]); | ~~~~~^~~~~~~~~~~~
ソースコード
#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; }