結果

問題 No.1529 Constant Lcm
ユーザー monnumonnu
提出日時 2021-06-04 21:27:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,774 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 183,444 KB
実行使用メモリ 706,244 KB
最終ジャッジ日時 2024-04-30 01:40:28
合計ジャッジ時間 24,426 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 5 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 MLE -
testcase_11 AC 708 ms
258,840 KB
testcase_12 AC 37 ms
16,896 KB
testcase_13 MLE -
testcase_14 AC 1,006 ms
359,936 KB
testcase_15 AC 1,056 ms
379,600 KB
testcase_16 AC 809 ms
295,040 KB
testcase_17 AC 437 ms
163,968 KB
testcase_18 AC 476 ms
176,768 KB
testcase_19 AC 1,021 ms
369,368 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+1,vector<int>(n,0));
  vector<int> other_p(N+1,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;
    }
  }

  map<int,int> other_primes;
  vector<int> max_cnt(n,0);
  for(int i=1;i<=N-1;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(auto pp:other_primes){
    ans*=(ll)pp.first;
    ans%=MOD;
    if(pp.second==2){
      ans*=(ll)pp.first;
      ans%=MOD;
    }
  }
  cout<<ans<<endl;
}
0