結果

問題 No.3717 GCD LCM GCD
コンテスト
ユーザー Rumain831
提出日時 2026-09-19 02:49:09
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 962 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,816 ms
コンパイル使用メモリ 194,320 KB
実行使用メモリ 11,076 KB
最終ジャッジ日時 2026-09-19 02:49:23
合計ジャッジ時間 3,678 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
using ll = long long;

ll modpow(ll a, ll b, ll p){
  a%=p;
  ll ans=1;
  while(b>0){
    if(b%2==1) ans=(ans*a)%p;
    b/=2;
    a=(a*a)%p;
  }
  return ans;
}

int main(void){
  int nn=1e6;
  vector<int> yakusu(nn+1, -1), prime;
  for(int i=2; i<=nn; i++){
    if(yakusu[i]!=-1) continue;
    int copy=i;
    prime.push_back(i);
    while(copy<=nn){
      if(yakusu[copy]==-1) yakusu[copy]=i;
      copy+=i;
    }
  }
  int n, k; cin >> n >> k;
  map<int, vector<int>> cnt;
  for(int i=0; i<n; i++){
    int a; cin >> a;
    while(a>1){
      int d=yakusu[a], c=0;
      while(a%d==0) c++, a/=d;
      cnt[d].push_back(c);
    }
  }
  ll ans=1, mod=998233453, tar=n/k;
  for(auto&[d, vec]:cnt){
    sort(begin(vec), end(vec));
    int t=vec.size(), zero=n-t;
    int p=(tar<=zero?0:vec[tar-zero-1]);
    ans*=modpow(d, p, mod);
  }
  cout << ans << endl;
  return 0; 
}
0