結果

問題 No.1529 Constant Lcm
ユーザー Example0911Example0911
提出日時 2021-06-04 20:38:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,592 ms / 3,000 ms
コード長 2,623 bytes
コンパイル時間 2,727 ms
コンパイル使用メモリ 213,848 KB
実行使用メモリ 16,404 KB
最終ジャッジ日時 2023-08-12 09:53:06
合計ジャッジ時間 20,566 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1,398 ms
15,208 KB
testcase_11 AC 504 ms
8,064 KB
testcase_12 AC 23 ms
4,384 KB
testcase_13 AC 1,160 ms
13,584 KB
testcase_14 AC 698 ms
9,900 KB
testcase_15 AC 790 ms
10,328 KB
testcase_16 AC 601 ms
8,844 KB
testcase_17 AC 308 ms
6,356 KB
testcase_18 AC 335 ms
6,492 KB
testcase_19 AC 745 ms
10,360 KB
testcase_20 AC 1,579 ms
16,272 KB
testcase_21 AC 1,564 ms
16,404 KB
testcase_22 AC 1,557 ms
16,324 KB
testcase_23 AC 1,592 ms
16,308 KB
testcase_24 AC 1,574 ms
16,404 KB
testcase_25 AC 1,529 ms
16,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#define int long long
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = 998244353;

struct mint {
	ll x; // typedef long long ll;
	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;
	}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
struct Sieve {
	int n;
	vector<int> f, primes;
	// n以下の素数を列挙する
	Sieve(int n = 1) :n(n), f(n + 1) {
		f[0] = f[1] = -1;
		for (ll i = 2; i <= n; ++i) {
			if (f[i]) continue;
			primes.push_back(i);
			f[i] = i;
			for (ll j = i * i; j <= n; j += i) {
				if (!f[j]) f[j] = i;
			}
		}
	}
	// xが素数かどうか判定する
	bool isPrime(int x) { return f[x] == x; }
	// 素因数を全列挙
	vector<int> factorList(int x) {
		vector<int> res;
		while (x != 1) {
			res.push_back(f[x]);
			x /= f[x];
		}
		return res;
	}
	// ランレングス圧縮
	vector<P> factor(int x) {
		vector<int> fl = factorList(x);
		if (fl.size() == 0) return {};
		vector<P> res(1, P(fl[0], 0));
		for (int p : fl) {
			if (res.back().first == p) {
				res.back().second++;
			}
			else {
				res.emplace_back(p, 1);
			}
		}
		return res;
	}
};
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	Sieve s(N + 100);
	map<int, int>mp;
	for (int i = 1; i < N; i++) {
		vector<P> p1 = s.factor(i), p2 = s.factor(N - i);
		map<int, int>now;
		for (auto x : p1) {
			now[x.first] += x.second;
		}
		for (auto x : p2) {
			now[x.first] += x.second;
		}
		for (auto x : now) {
			mp[x.first] = max(mp[x.first], x.second);
		}
	}
	mint ans = 1;
	for (auto x : mp) {
		ans *= mint(x.first).pow(x.second);
	}
	cout << ans << endl;
	return 0;

}

0