結果

問題 No.1529 Constant Lcm
ユーザー V_MelvilleV_Melville
提出日時 2021-06-26 04:10:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 60 ms / 3,000 ms
コード長 2,030 bytes
コンパイル時間 2,213 ms
コンパイル使用メモリ 202,372 KB
実行使用メモリ 7,652 KB
最終ジャッジ日時 2023-09-07 13:41:41
合計ジャッジ時間 4,195 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
7,332 KB
testcase_01 AC 11 ms
7,596 KB
testcase_02 AC 10 ms
7,544 KB
testcase_03 AC 10 ms
7,400 KB
testcase_04 AC 10 ms
7,340 KB
testcase_05 AC 10 ms
7,604 KB
testcase_06 AC 10 ms
7,328 KB
testcase_07 AC 10 ms
7,608 KB
testcase_08 AC 10 ms
7,448 KB
testcase_09 AC 10 ms
7,340 KB
testcase_10 AC 54 ms
7,520 KB
testcase_11 AC 27 ms
7,332 KB
testcase_12 AC 11 ms
7,404 KB
testcase_13 AC 48 ms
7,596 KB
testcase_14 AC 36 ms
7,344 KB
testcase_15 AC 36 ms
7,540 KB
testcase_16 AC 27 ms
7,396 KB
testcase_17 AC 21 ms
7,536 KB
testcase_18 AC 21 ms
7,576 KB
testcase_19 AC 36 ms
7,652 KB
testcase_20 AC 55 ms
7,336 KB
testcase_21 AC 54 ms
7,344 KB
testcase_22 AC 55 ms
7,604 KB
testcase_23 AC 52 ms
7,336 KB
testcase_24 AC 55 ms
7,396 KB
testcase_25 AC 60 ms
7,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fi first
#define se second

using std::cin;
using std::cout;
using std::max;
using std::map;
using std::vector;
using ll = long long;
using P = std::pair<int, int>;

const int N = 1000005;

const int mod = 998244353;
struct mint {
  ll x; 
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// linear sieve
vector<int> ps, pf;
void sieve(int mx) {
	pf.resize(mx + 1);
	rep(i, mx + 1) pf[i] = i;
	for (int i = 2; i <= mx; ++i) {
		if (pf[i] == i) ps.push_back(i);
		for (int j = 0; j < ps.size() and ps[j] <= pf[i]; ++j) {
			int x = ps[j] * i;
			if (x > mx) break;
			pf[x] = ps[j];
		}
	}
} 

int main() {
    sieve(1e6);
    int n;
    cin >> n;
    
    auto f = [&](int x, int y) {
    	int cnt = 0;
    	while (x % y == 0) {
    		x /= y;
    		cnt++;
		}
		return cnt;
	};
    
    mint ans = 1;
    for (int i = 2; i < n; ++i) {
    	if (pf[i] != i) continue;
    	int mx = 0;
    	for (int j = i; j < n; j += i) {
    		mx = max(mx, f(j, i) + f(n - j, i));
		}
		ans *= mint(i).pow(mx);
	}
    
    cout << ans.x << '\n';

    return 0;
}
0