結果

問題 No.1529 Constant Lcm
ユーザー monnumonnu
提出日時 2021-06-04 21:37:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,742 bytes
コンパイル時間 1,730 ms
コンパイル使用メモリ 175,188 KB
実行使用メモリ 706,420 KB
最終ジャッジ日時 2024-04-30 02:05:16
合計ジャッジ時間 18,323 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 5 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 MLE -
testcase_11 AC 532 ms
258,768 KB
testcase_12 AC 29 ms
16,896 KB
testcase_13 MLE -
testcase_14 AC 766 ms
359,844 KB
testcase_15 AC 783 ms
379,672 KB
testcase_16 AC 608 ms
294,988 KB
testcase_17 AC 339 ms
163,968 KB
testcase_18 AC 367 ms
176,796 KB
testcase_19 AC 764 ms
369,280 KB
testcase_20 MLE -
testcase_21 MLE -
testcase_22 MLE -
testcase_23 MLE -
testcase_24 MLE -
testcase_25 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define MAX 1000
#define INF 1000000000000000000
#define MOD 998244353

vector<int> p;
vector<bool> p_table(MAX+1,true);
void prime(){
  p_table.at(0)=false,p_table.at(1)=false;
  for(int i=2;i<=MAX;i++){
    if(p_table.at(i)){
      p.push_back(i);
      for(int j=2;i*j<=MAX;j++){
        p_table.at(i*j)=false;
      }
    }
  }
}


int main(){
  int N;
  cin>>N;
  prime();
  int n=p.size();
  vector<vector<int>> cnt(N,vector<int>(n,0));
  vector<int> other_p(N,0);
  for(int i=1;i<N;i++){
    int x=i;
    for(int j=0;j<n;j++){
      while(x%p[j]==0){
        cnt[i][j]++;
        x/=p[j];
      }
    }
    if(x>1){
      other_p[i]=x;
    }
  }

  vector<int> max_cnt(n,0);
  vector<int> other_primes(N,0);
  for(int i=1;i<N/2;i++){
    int x=i;
    int y=N-i;
    for(int j=0;j<n;j++){
      max_cnt[j]=max(max_cnt[j],cnt[x][j]+cnt[y][j]);
    }
    if(other_p[x]==0&&other_p[y]>0){
      other_primes[other_p[y]]=max(other_primes[other_p[y]],1);
    }else if(other_p[x]>0&&other_p[y]==0){
      other_primes[other_p[x]]=max(other_primes[other_p[x]],1);
    }else if(other_p[x]>0&&other_p[y]>0&&other_p[x]!=other_p[y]){
      other_primes[other_p[y]]=max(other_primes[other_p[y]],1);
      other_primes[other_p[x]]=max(other_primes[other_p[x]],1);
    }else if(other_p[x]>0&&other_p[y]>0){
      other_primes[other_p[x]]=2;
    }
  }
  ll ans=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<max_cnt[i];j++){
      ans*=(ll)p[i];
      ans%=MOD;
    }
  }
  for(int i=1;i<=N;i++){
    for(int j=0;j<other_primes[i];j++){
      ans*=(ll)i;
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
}
0