QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#186255 | #6740. Function | UrgantTeam# | AC ✓ | 408ms | 19988kb | C++23 | 3.2kb | 2023-09-23 15:38:27 | 2023-09-23 15:38:28 |
Judging History
answer
#include <iostream>
#include <vector>
#include <cmath>
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;
typedef long double ld;
typedef long long ll;
using vi = vector<int>;
using vl = vector<ll>;
const int C = 20210926;
const int D = 2000000;
int get_min_prime(const int n) {
static vi mnp;
static vi primes;
if (mnp.empty()) {
mnp.resize(D + 1, 1);
for (int i = 2; i <= D; ++i) {
if (mnp[i] == 1) {
mnp[i] = i;
primes.push_back(i);
}
for (int j : primes) {
if (j > mnp[i]) break;
int prod = j * i;
if (prod > D) break;
mnp[prod] = j;
}
}
}
return mnp[n];
}
vi get_divisors(int n) {
if (n == 1) return {1};
int p = get_min_prime(n);
int a = 0;
while (n % p == 0) {
n /= p;
++a;
}
vi dvs = get_divisors(n);
const int dvss = dvs.size();
for (int i = 0; i < dvss * a; ++i)
dvs.push_back(dvs[i] * p);
return dvs;
}
const int M = 998244353;
int sum(int a, int b, int m = M) {
if ((a += b) >= m)
a -= m;
return a;
}
int dif(int a, int b, int m = M) {
if ((a -= b) < 0)
a += m;
return a;
}
int prod(int a, int b, int m = M) {
return ((ll)a * b) % m;
}
int find_f(const int n) {
static vi v;
if (v.empty()) {
v.resize(D + 1);
for (int i = 1; i <= D; ++i) {
v[i] = sum(1, v[i - 1]);
for (int d : get_divisors(i))
if (d != 1 && d != i)
v[i] = sum(v[i], dif(v[d], v[d - 1]));
}
}
return v[n];
}
int find_ans(const int n) {
if (n <= D)
return find_f(n);
int max_m = n / (D + 1);
vi ans(max_m + 1);
for (int m = max_m; m >= 1; --m) {
const int N = n / m;
ans[m] = 1;
const int MAX_I = min(C, max_m / m);
for (int i = 2; i <= MAX_I; ++i)
ans[m] = sum(ans[m], ans[m * i]);
const int U = max(int(sqrtf(n)) / m, MAX_I);
for (int i = MAX_I + 1; i <= U; ++i)
ans[m] = sum(ans[m], find_f(N / i));
for (int j = max(1, N / C); j <= N / (U + 1); ++j) {
ll f = find_f(j);
int L = U + 1;
int R1 = min(C, N / j);
int R2 = min(C, N / (j + 1));
int qua1 = max(0, R1 - L + 1);
int qua2 = max(0, R2 - L + 1);
int qua = qua1 - qua2;
ans[m] = sum(ans[m], prod(f, qua));
}
}
return ans[1];
}
bool solve_test() {
int n;
if (!(cin >> n)) return false;
cout << find_ans(n) << '\n';
return true;
}
void solve_tests() {
while (solve_test());
}
#include <chrono>
int main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0);
auto beg = chrono::high_resolution_clock::now();
solve_tests();
auto end = chrono::high_resolution_clock::now();
//cerr << (end - beg) / 1ms << " ms\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 302ms
memory: 19812kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 303ms
memory: 19872kb
input:
2
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 295ms
memory: 19884kb
input:
100
output:
949
result:
ok 1 number(s): "949"
Test #4:
score: 0
Accepted
time: 301ms
memory: 19968kb
input:
10
output:
19
result:
ok 1 number(s): "19"
Test #5:
score: 0
Accepted
time: 299ms
memory: 19896kb
input:
1000
output:
48614
result:
ok 1 number(s): "48614"
Test #6:
score: 0
Accepted
time: 300ms
memory: 19828kb
input:
10000
output:
2602393
result:
ok 1 number(s): "2602393"
Test #7:
score: 0
Accepted
time: 298ms
memory: 19968kb
input:
100000
output:
139804054
result:
ok 1 number(s): "139804054"
Test #8:
score: 0
Accepted
time: 296ms
memory: 19880kb
input:
1000000
output:
521718285
result:
ok 1 number(s): "521718285"
Test #9:
score: 0
Accepted
time: 301ms
memory: 19832kb
input:
10000000
output:
503104917
result:
ok 1 number(s): "503104917"
Test #10:
score: 0
Accepted
time: 309ms
memory: 19820kb
input:
100000000
output:
198815604
result:
ok 1 number(s): "198815604"
Test #11:
score: 0
Accepted
time: 397ms
memory: 19988kb
input:
1000000000
output:
373787809
result:
ok 1 number(s): "373787809"
Test #12:
score: 0
Accepted
time: 408ms
memory: 19888kb
input:
999999999
output:
997616263
result:
ok 1 number(s): "997616263"
Test #13:
score: 0
Accepted
time: 391ms
memory: 19856kb
input:
999999990
output:
997615701
result:
ok 1 number(s): "997615701"
Test #14:
score: 0
Accepted
time: 395ms
memory: 19804kb
input:
999999900
output:
993928691
result:
ok 1 number(s): "993928691"
Test #15:
score: 0
Accepted
time: 396ms
memory: 19872kb
input:
999999000
output:
754532207
result:
ok 1 number(s): "754532207"
Test #16:
score: 0
Accepted
time: 392ms
memory: 19856kb
input:
999990000
output:
996592686
result:
ok 1 number(s): "996592686"
Test #17:
score: 0
Accepted
time: 390ms
memory: 19812kb
input:
999900000
output:
311678722
result:
ok 1 number(s): "311678722"
Test #18:
score: 0
Accepted
time: 388ms
memory: 19976kb
input:
999000000
output:
60462624
result:
ok 1 number(s): "60462624"
Test #19:
score: 0
Accepted
time: 392ms
memory: 19872kb
input:
990000000
output:
444576800
result:
ok 1 number(s): "444576800"
Test #20:
score: 0
Accepted
time: 377ms
memory: 19880kb
input:
900000000
output:
95615129
result:
ok 1 number(s): "95615129"
Test #21:
score: 0
Accepted
time: 302ms
memory: 19960kb
input:
1361956
output:
813433539
result:
ok 1 number(s): "813433539"
Test #22:
score: 0
Accepted
time: 307ms
memory: 19900kb
input:
7579013
output:
677659797
result:
ok 1 number(s): "677659797"
Test #23:
score: 0
Accepted
time: 319ms
memory: 19820kb
input:
8145517
output:
801509527
result:
ok 1 number(s): "801509527"
Test #24:
score: 0
Accepted
time: 302ms
memory: 19800kb
input:
6140463
output:
869023935
result:
ok 1 number(s): "869023935"
Test #25:
score: 0
Accepted
time: 294ms
memory: 19872kb
input:
3515281
output:
989091505
result:
ok 1 number(s): "989091505"
Test #26:
score: 0
Accepted
time: 303ms
memory: 19896kb
input:
6969586
output:
539840131
result:
ok 1 number(s): "539840131"