QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#132700 | #6740. Function | de_sousa# | TL | 779ms | 120764kb | C++17 | 1.4kb | 2023-07-31 03:21:59 | 2023-07-31 03:22:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define all(x) begin(x),end(x)
#define trav(a, b) for (auto a : b)
#define lld long long
#pragma GCC optimize("-O3","unroll-loops")
using i64 = long long;
const int MOD=998244353;
const int MAX=10'000'000;
int pref[2*MAX];
int DP[MAX];
const int CHATO=20210926;
int red(int &x){
if(x>=MOD)x-=MOD;
if(x<0)x+=MOD;
return x;
}
map<lld,int> V;
void calcset(lld x){
V[x]++;
for(int i=2;(x/i)>=MAX;i++){
calcset(x/i);
}
}
void solve() {
lld n;
cin>>n;
if(n<MAX){
cout<<DP[n]<<"\n";
return;
}
calcset(n);
vector<pair<int,int> >X;
trav(a,V)X.push_back(a);
lld ans=0;
trav(a,X){
lld can=1;
int A=a.first;
rep(i,1,MAX){
int L=(A/(i+1));
int R=(A/i);
can+=DP[i]*(min(R,CHATO)-min(L,CHATO));
can%=MOD;
}
can%=MOD;
can+=MOD;
can%=MOD;
can*=a.second;
can%=MOD;
ans+=can;
}
ans%=MOD;
cout<<ans<<"\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
DP[0]=0;
rep(i,0,MAX)pref[i]=0;
int sum=1;
rep(i,1,MAX){
sum+=pref[i];
sum%=MOD;
DP[i]=sum;
for(int j=2;j*i<MAX;j++){
pref[j*i]+=DP[i];
red(pref[j*i]);
pref[j*i+j]-=DP[i];
red(pref[j*i+j]);
}
}
// cin >> tt;
while (tt--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 779ms
memory: 120640kb
input:
1
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 666ms
memory: 120644kb
input:
2
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 670ms
memory: 120656kb
input:
100
output:
949
result:
ok 1 number(s): "949"
Test #4:
score: 0
Accepted
time: 722ms
memory: 120656kb
input:
10
output:
19
result:
ok 1 number(s): "19"
Test #5:
score: 0
Accepted
time: 677ms
memory: 120660kb
input:
1000
output:
48614
result:
ok 1 number(s): "48614"
Test #6:
score: 0
Accepted
time: 711ms
memory: 120764kb
input:
10000
output:
2602393
result:
ok 1 number(s): "2602393"
Test #7:
score: 0
Accepted
time: 694ms
memory: 120760kb
input:
100000
output:
139804054
result:
ok 1 number(s): "139804054"
Test #8:
score: 0
Accepted
time: 668ms
memory: 120704kb
input:
1000000
output:
521718285
result:
ok 1 number(s): "521718285"
Test #9:
score: 0
Accepted
time: 663ms
memory: 120712kb
input:
10000000
output:
503104917
result:
ok 1 number(s): "503104917"
Test #10:
score: -100
Time Limit Exceeded
input:
100000000