QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572072#9309. GraphDQ9911AC ✓125ms12260kbC++206.2kb2024-09-18 11:42:322024-09-18 11:42:32

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 11:42:32]
  • 评测
  • 测评结果:AC
  • 用时:125ms
  • 内存:12260kb
  • [2024-09-18 11:42:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> point;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using u128 = __uint128_t;
template <typename T>
T inverse(T a, T m) {
	T u = 0, v = 1;
	while (a != 0) {
		T t = m / a;
		m -= t * a; swap(a, m);
		u -= t * v; swap(u, v);
	}
	assert(m == 1);
	return u;
}

template<int m, enable_if_t<(m >= 1)>* = nullptr >
struct Mint {
	u32 v;
	static constexpr int mod() { return m; }
	static constexpr u32 umod() { return m; }
	template<typename T, enable_if_t<is_integral_v<T> >* = nullptr>
	static Mint raw(T _v) {
		Mint x;
		x.v = _v;
		return x;
	}

	Mint() : v(0) {}
	Mint(const Mint &rhs) : v(rhs.v) {}
	template<typename T, enable_if_t<is_integral_v<T> >* = nullptr>
	Mint(T _v) {
		int x = (int) (_v % mod());
		if (x < 0) x += mod();
		v = (u32) x;
	}

	u32 val() const { return v; }
	Mint inv() const { return Mint(inverse((int) v, mod()));}

	Mint &operator ++() { if (++v == umod()) v = 0; return *this;}
	Mint &operator --() { if (v-- == 0) v = umod() - 1; return *this; }
	Mint operator ++(int) { Mint x = *this; ++(*this); return x; }
	Mint operator --(int) { Mint x = *this; --(*this); return x; }
	Mint &operator += (const Mint &rhs) { if ((v += rhs.v) >= umod()) v -= umod(); return *this; }
	Mint &operator -= (const Mint &rhs) { if ((v += umod() - rhs.v) >= umod()) v -= umod(); return *this; }
	Mint &operator *= (const Mint &rhs) { v = (u64) v * rhs.v % umod(); return *this; }
	Mint &operator /= (const Mint &rhs) { return (*this) *= rhs.inv(); }
	Mint operator+() const { return *this; }
	Mint operator-() const { return Mint() - *this; }

	Mint pow(long long n) const {
		assert(n >= 0);
		Mint x = *this, r = 1;
		while (n) {
			if (n & 1) r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}

	friend Mint operator + (const Mint &lhs, const Mint &rhs) { return Mint(lhs) += rhs; }
	friend Mint operator - (const Mint &lhs, const Mint &rhs) { return Mint(lhs) -= rhs; }
	friend Mint operator * (const Mint &lhs, const Mint &rhs) { return Mint(lhs) *= rhs; }
	friend Mint operator / (const Mint &lhs, const Mint &rhs) { return Mint(lhs) /= rhs; }

	friend bool operator == (const Mint& lhs, const Mint& rhs) { return lhs._v == rhs._v;	}
	friend bool operator != (const Mint& lhs, const Mint& rhs) { return lhs._v != rhs._v;	}

	template<typename U>
	friend U &operator << (U &stream, const Mint &rhs) {
		return stream << rhs.v;
	}
};

constexpr int mod = 998244353;
using mint = Mint<mod>;

vector<bool> np;
vector<u32> primes;
vector<int> mu;
void sieve(int N) {
	np.resize(N + 1);
	mu.resize(N + 1);
	mu[1] = 1;

	for (int i = 2; i <= N; i++) {
		if (!np[i]) {
			primes.push_back(i);
			mu[i] = -1;
		}

		for (int p : primes) {
			if (i * p > N)
				break;

			mu[i * p] = -mu[i];
			np[i * p] = true;

			if (i % p == 0) {
				mu[i * p] = 0;
				break;
			}
		}
	}
}

namespace min25 {
u64 n;
uint32_t sqrtn;
int pn;
vector<u64> v;
void init(u64 _n) {
	n = _n;
	sqrtn = sqrt(_n);

	while ((u64)(sqrtn + 1) * (sqrtn + 1) <= _n) {
		sqrtn++;
	}

	sieve(sqrtn);
	pn = primes.size();
	v.reserve(sqrtn * 2 + 10);

	for (u64 l = 1, r; l <= n; l = r + 1) {
		r = n / (n / l);
		v.push_back(n / l);
	}
}

int ind(u64 x) {
	if (x <= sqrtn) [[likely]] {
		return v.size() - x;
	}
	return n / x - 1;
}

u64 fastdiv(u64 x, u64 _m) {
	// _m = ceil(2^64 / m);
	// return x / m;
	return (u64)((u128) x * _m >> 64);
}

template<typename T>
struct ExEratosthensSieve {
	// fp[i] = \sum_{2 <= k <= v[i], k is prime} f(k)
	// sf(x) = \sum_{2 <= i <= x} f(i)
	// f(x * y) = f(x) * f(y)
	template<typename F, typename G>
	pair<vector<T>, vector<T>> calcfp(F f, G sf) {
		vector<T> pf(pn + 1);
		for (int i = 0; i < pn; i++) {
			pf[i + 1] = pf[i] + f(primes[i]);
		}
		vector<T> fp(v.size());
		for (int i = 0; i < (int) v.size(); i++) {
			fp[i] = sf(v[i]);
		}
		for (int j = 0; j < pn; j++) {
			auto pj = primes[j];
			auto _pj = ~0ull / pj + 1;
			u64 z = (u64)pj * pj;
			// T vv = f(pj);
			for (int i = 0; z <= v[i]; i++) {
				int k = ind(fastdiv(v[i], _pj));
				fp[i] -= (fp[k] - pf[j]);
			}
		}

		return make_pair(move(fp), move(pf));
	}
	// g[i] = \sum_{2 <= k <= v[i]} f(k)
	// fpe(p, e) = f(p^e), p is prime
	template<typename F>
	vector<T> calcf(vector<T> fp, vector<T> pf, F fpe) {
		auto &g = fp;
		auto &pg = pf;
		for (int j = pn - 1; j >= 0; j--) {
			auto pj = primes[j];
			auto _pj = ~0ull / pj + 1;
			u64 z = (u64)pj * pj;
			for (int i = 0; z <= v[i]; i++) {
				u64 pe = pj, curv = fastdiv(v[i], _pj);
				for (int e = 1; curv >= pj; e++, pe *= pj) {
					g[i] += fpe(pj, e) * (g[ind(curv)] - pg[j + 1]) + fpe(pj, e + 1);
					curv = fastdiv(curv, _pj);
				}
			}
		}

		return g;
	}
	template<typename F>
	T calc(vector<T> fp, vector<T> pf, F fpe) {
		auto &g = fp;
		auto &pg = pf;
		auto dfs = [&](auto && self, i64 n, int k)->T {
			T ans = g[ind(n)] - pg[k];
			for (int j = k; j < pn; j++) {
				auto pj = primes[j];
				auto _pj = ~0ull / pj + 1;
				u64 z = (u64) pj * pj;
				if (z > n) break;
				u64 pe = pj, curn = fastdiv(n, _pj);
				for (int e = 1; curn >= pj; e++, pe *= pj) {
					ans += fpe(pj, e) * self(self, curn, j + 1) + fpe(pj, e + 1);
					curn = fastdiv(curn, _pj);
				}
			}
			return ans;
		};
		return dfs(dfs, n, 0);
	}
};
}

namespace min25 {
void solve() {
	ll n;
	cin >> n;
	init(n);
	ExEratosthensSieve<u32> solver;
	auto [fp, pf] = solver.calcfp([](u64 x) { return 1;}, [](u64 x) { return x - 1;});
	auto f = [&](u64 x) {
		if (x <= 2) return mint(1);
		if (x == 3) return mint(3);
		auto num = fp[ind(x)] - fp[ind(x / 2)];
		return (x - num - 1) * mint(x).pow(num);
	};
	mint ans = 1;
	u64 last = 0;
	for (auto &e : v) {
		u64 cur = n / e;
		ans *= f(e).pow(cur - last);
		last = cur;
	}
	cout << ans << '\n';
}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	min25::solve();
	return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3864kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3644kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3800kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3808kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3836kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 1ms
memory: 3740kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3696kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 2ms
memory: 3932kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 8ms
memory: 4156kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 7ms
memory: 4236kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 12ms
memory: 4512kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 20ms
memory: 5208kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 42ms
memory: 7068kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 75ms
memory: 9620kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 108ms
memory: 11472kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 125ms
memory: 12108kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 121ms
memory: 12260kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 125ms
memory: 12136kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed