QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#164866#6740. Functionmendicillin2#ML 68ms393956kbC++173.2kb2023-09-05 14:16:412023-09-05 14:16:43

Judging History

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

  • [2023-09-05 14:16:43]
  • 评测
  • 测评结果:ML
  • 用时:68ms
  • 内存:393956kb
  • [2023-09-05 14:16:41]
  • 提交

answer

#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;

template <class T> int sz(T&& a) { return int(size(forward<T>(a))); }

template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;

using ll = int64_t;
using vi = vc<int>;

mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

template <class F>
struct ycr {
	F f;
	template <class T> explicit ycr(T&& f_) : f(forward<T>(f_)) {}

	template <class... Args> decltype(auto) operator()(Args&&... args) {
		return f(ref(*this), forward<Args>(args)...);
	}
};
template <class F> decltype(auto) yc(F&& f) {
	return ycr<decay_t<F>>(forward<F>(f));
}

template <class T> T pow(T a, ll b) {
	assert(b >= 0);
	T r = 1; while (b) { if (b & 1) r *= a; b >>= 1, a *= a; } return r;
}

template <int MOD> struct mint {
	static constexpr int m = MOD;

	int v;
	mint() : v(0) {}
	mint(ll v_) : v(int(v_ % m)) { if (v < 0) v += m; }
	friend mint inv(const mint& n) { return pow(n, m-2); }
	friend bool operator == (const mint& a, const mint& b) { return a.v == b.v; }
	friend bool operator != (const mint& a, const mint& b) { return a.v != b.v; }

	mint& operator += (const mint& o) { v -= m-o.v; if (v < 0) v += m; return *this; }
	mint& operator -= (const mint& o) { v -= o.v; if (v < 0) v += m; return *this; }
	mint& operator *= (const mint& o) { v = int(ll(v) * o.v % m); return *this; }
	mint& operator /= (const mint& o) { return *this *= inv(o); }

	friend mint operator + (const mint &a, const mint & b) { return mint(a) += b; }
	friend mint operator - (const mint &a, const mint & b) { return mint(a) -= b; }
	friend mint operator * (const mint &a, const mint & b) { return mint(a) *= b; }
	friend mint operator / (const mint &a, const mint & b) { return mint(a) /= b; }
};
using num = mint<998244353>;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr);

	int N; cin >> N;
	const int n2 = int(sqrt(N));
	vector<int> vs;

	{
		int a = N;
		while (a) {
			vs.push_back(a);
			a = N / (N/a+1);
		}
	}

	const int s = int(vs.size());

	auto get_idx = [&](int a) -> int {
		return int(a <= n2 ? s-a : N/a-1);
	};
	assert(vs[s-1] == 1);

	const int M = 20210926;
	const int MOD = 998244353;
	const ll LMOD = ll(MOD) << 32;
	vector<int> f(N+1);
	for (int i = s-1; i >= 0; i--) {
		int a = vs[i];
		int n = N/a;
		ll v = 1;
		for (int k = 2; k <= M; ) {
			const int cur = n*k;
			if (cur > N) break;
			const int which = N / cur;
			// N / (N / cur)
			const int nxt = N / which;
			const int j = get_idx(which);
			const int nxt_k = min(M, nxt / n);
			v += ll(f[j]) * (nxt_k - k + 1);
			if (v >= LMOD) v -= LMOD;
			k = nxt_k+1;
		}
		f[i] = int(v % MOD);
	}
	cout << f[0] << '\n';
	//cerr << double(clock()) / CLOCKS_PER_SEC << endl;

	/*
	for (int a = 1; a <= N; a++) {
		cerr << "a=" << a << ", f=" << f[a].v << endl;
	}
	*/
	/*
	vector<num> f(N+1);
	f[1] = 1;
	num ans = 1;
	for (int a = 2; a <= N; a++) {
		for (int d = 2; d <= M && d <= a; d++) {
			if (a % d == 0) {
				f[a] += f[a/d];
			}
		}
		ans += f[a];
	}
	for (int a = 2; a <= N; a++) {
		cerr << "a=" << a << ", f=" << f[a].v << '\n';
	}
	cout << ans.v << '\n';
	*/
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

2

output:

2

result:

ok 1 number(s): "2"

Test #3:

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

input:

100

output:

949

result:

ok 1 number(s): "949"

Test #4:

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

input:

10

output:

19

result:

ok 1 number(s): "19"

Test #5:

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

input:

1000

output:

48614

result:

ok 1 number(s): "48614"

Test #6:

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

input:

10000

output:

2602393

result:

ok 1 number(s): "2602393"

Test #7:

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

input:

100000

output:

139804054

result:

ok 1 number(s): "139804054"

Test #8:

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

input:

1000000

output:

521718285

result:

ok 1 number(s): "521718285"

Test #9:

score: 0
Accepted
time: 14ms
memory: 42272kb

input:

10000000

output:

503104917

result:

ok 1 number(s): "503104917"

Test #10:

score: 0
Accepted
time: 68ms
memory: 393956kb

input:

100000000

output:

198815604

result:

ok 1 number(s): "198815604"

Test #11:

score: -100
Memory Limit Exceeded

input:

1000000000

output:


result: