QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137157 | #6740. Function | propane | AC ✓ | 449ms | 5792kb | C++20 | 2.7kb | 2023-08-10 00:24:23 | 2023-08-10 00:24:24 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<unordered_map>
using namespace std;
using LL = long long;
template<const int T>
struct ModInt {
const static int mod = T;
int x;
ModInt(int x = 0) : x(x % mod) {}
ModInt(long long x) : x(int(x % mod)) {}
int val() { return x; }
ModInt operator + (const ModInt &a) const { int x0 = x + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
ModInt operator - (const ModInt &a) const { int x0 = x - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
ModInt operator * (const ModInt &a) const { return ModInt(1LL * x * a.x % mod); }
ModInt operator / (const ModInt &a) const { return *this * a.inv(); }
bool operator == (const ModInt &a) const { return x == a.x; };
bool operator != (const ModInt &a) const { return x != a.x; };
void operator += (const ModInt &a) { x += a.x; if (x >= mod) x -= mod; }
void operator -= (const ModInt &a) { x -= a.x; if (x < 0) x += mod; }
void operator *= (const ModInt &a) { x = 1LL * x * a.x % mod; }
void operator /= (const ModInt &a) { *this = *this / a; }
friend ModInt operator + (int y, const ModInt &a){ int x0 = y + a.x; return ModInt(x0 < mod ? x0 : x0 - mod); }
friend ModInt operator - (int y, const ModInt &a){ int x0 = y - a.x; return ModInt(x0 < 0 ? x0 + mod : x0); }
friend ModInt operator * (int y, const ModInt &a){ return ModInt(1LL * y * a.x % mod);}
friend ModInt operator / (int y, const ModInt &a){ return ModInt(y) / a;}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.x;}
friend istream &operator>>(istream &is, ModInt &t){return is >> t.x;}
ModInt pow(int64_t n) const {
ModInt res(1), mul(x);
while(n){
if (n & 1) res *= mul;
mul *= mul;
n >>= 1;
}
return res;
}
ModInt inv() const {
int a = x, b = mod, u = 1, v = 0;
while (b) {
int t = a / b;
a -= t * b; swap(a, b);
u -= t * v; swap(u, v);
}
if (u < 0) u += mod;
return u;
}
};
using mint = ModInt<998244353>;
unordered_map<int, mint> ans;
const int up = 20210926;
mint dp(int x){
if (x == 1) return 1;
if(ans.contains(x)) return ans[x];
mint t = 1;
for(int l = 1, r; l <= x; l = r + 1){
r = x / (x / l);
int R = min(up, r);
if (l != 1 && l <= R) t += (R - l + 1) * dp(x / l);
}
return ans[x] = t;
}
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n;
cin >> n;
cout << dp(n) << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3484kb
input:
2
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3516kb
input:
100
output:
949
result:
ok 1 number(s): "949"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3560kb
input:
10
output:
19
result:
ok 1 number(s): "19"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3508kb
input:
1000
output:
48614
result:
ok 1 number(s): "48614"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3536kb
input:
10000
output:
2602393
result:
ok 1 number(s): "2602393"
Test #7:
score: 0
Accepted
time: 1ms
memory: 3512kb
input:
100000
output:
139804054
result:
ok 1 number(s): "139804054"
Test #8:
score: 0
Accepted
time: 3ms
memory: 3564kb
input:
1000000
output:
521718285
result:
ok 1 number(s): "521718285"
Test #9:
score: 0
Accepted
time: 14ms
memory: 3776kb
input:
10000000
output:
503104917
result:
ok 1 number(s): "503104917"
Test #10:
score: 0
Accepted
time: 78ms
memory: 4140kb
input:
100000000
output:
198815604
result:
ok 1 number(s): "198815604"
Test #11:
score: 0
Accepted
time: 444ms
memory: 5704kb
input:
1000000000
output:
373787809
result:
ok 1 number(s): "373787809"
Test #12:
score: 0
Accepted
time: 449ms
memory: 5700kb
input:
999999999
output:
997616263
result:
ok 1 number(s): "997616263"
Test #13:
score: 0
Accepted
time: 446ms
memory: 5760kb
input:
999999990
output:
997615701
result:
ok 1 number(s): "997615701"
Test #14:
score: 0
Accepted
time: 445ms
memory: 5792kb
input:
999999900
output:
993928691
result:
ok 1 number(s): "993928691"
Test #15:
score: 0
Accepted
time: 439ms
memory: 5764kb
input:
999999000
output:
754532207
result:
ok 1 number(s): "754532207"
Test #16:
score: 0
Accepted
time: 447ms
memory: 5736kb
input:
999990000
output:
996592686
result:
ok 1 number(s): "996592686"
Test #17:
score: 0
Accepted
time: 441ms
memory: 5732kb
input:
999900000
output:
311678722
result:
ok 1 number(s): "311678722"
Test #18:
score: 0
Accepted
time: 440ms
memory: 5728kb
input:
999000000
output:
60462624
result:
ok 1 number(s): "60462624"
Test #19:
score: 0
Accepted
time: 434ms
memory: 5696kb
input:
990000000
output:
444576800
result:
ok 1 number(s): "444576800"
Test #20:
score: 0
Accepted
time: 408ms
memory: 5740kb
input:
900000000
output:
95615129
result:
ok 1 number(s): "95615129"
Test #21:
score: 0
Accepted
time: 4ms
memory: 3536kb
input:
1361956
output:
813433539
result:
ok 1 number(s): "813433539"
Test #22:
score: 0
Accepted
time: 12ms
memory: 3720kb
input:
7579013
output:
677659797
result:
ok 1 number(s): "677659797"
Test #23:
score: 0
Accepted
time: 13ms
memory: 3656kb
input:
8145517
output:
801509527
result:
ok 1 number(s): "801509527"
Test #24:
score: 0
Accepted
time: 7ms
memory: 3704kb
input:
6140463
output:
869023935
result:
ok 1 number(s): "869023935"
Test #25:
score: 0
Accepted
time: 7ms
memory: 3676kb
input:
3515281
output:
989091505
result:
ok 1 number(s): "989091505"
Test #26:
score: 0
Accepted
time: 8ms
memory: 3672kb
input:
6969586
output:
539840131
result:
ok 1 number(s): "539840131"