QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#132703#6740. Functionde_sousa#AC ✓869ms120772kbC++171.5kb2023-07-31 03:25:232023-07-31 03:25:26

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-31 03:25:26]
  • 评测
  • 测评结果:AC
  • 用时:869ms
  • 内存:120772kb
  • [2023-07-31 03:25:23]
  • 提交

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;
      if(i>=100000){
        i=A/(A/(i+1));
        i--;
      }
    }
    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: 737ms
memory: 120640kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 766ms
memory: 120644kb

input:

2

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 803ms
memory: 120712kb

input:

100

output:

949

result:

ok 1 number(s): "949"

Test #4:

score: 0
Accepted
time: 827ms
memory: 120644kb

input:

10

output:

19

result:

ok 1 number(s): "19"

Test #5:

score: 0
Accepted
time: 837ms
memory: 120724kb

input:

1000

output:

48614

result:

ok 1 number(s): "48614"

Test #6:

score: 0
Accepted
time: 829ms
memory: 120764kb

input:

10000

output:

2602393

result:

ok 1 number(s): "2602393"

Test #7:

score: 0
Accepted
time: 765ms
memory: 120652kb

input:

100000

output:

139804054

result:

ok 1 number(s): "139804054"

Test #8:

score: 0
Accepted
time: 750ms
memory: 120752kb

input:

1000000

output:

521718285

result:

ok 1 number(s): "521718285"

Test #9:

score: 0
Accepted
time: 786ms
memory: 120724kb

input:

10000000

output:

503104917

result:

ok 1 number(s): "503104917"

Test #10:

score: 0
Accepted
time: 769ms
memory: 120664kb

input:

100000000

output:

198815604

result:

ok 1 number(s): "198815604"

Test #11:

score: 0
Accepted
time: 783ms
memory: 120652kb

input:

1000000000

output:

373787809

result:

ok 1 number(s): "373787809"

Test #12:

score: 0
Accepted
time: 764ms
memory: 120668kb

input:

999999999

output:

997616263

result:

ok 1 number(s): "997616263"

Test #13:

score: 0
Accepted
time: 754ms
memory: 120772kb

input:

999999990

output:

997615701

result:

ok 1 number(s): "997615701"

Test #14:

score: 0
Accepted
time: 793ms
memory: 120724kb

input:

999999900

output:

993928691

result:

ok 1 number(s): "993928691"

Test #15:

score: 0
Accepted
time: 776ms
memory: 120700kb

input:

999999000

output:

754532207

result:

ok 1 number(s): "754532207"

Test #16:

score: 0
Accepted
time: 731ms
memory: 120664kb

input:

999990000

output:

996592686

result:

ok 1 number(s): "996592686"

Test #17:

score: 0
Accepted
time: 869ms
memory: 120656kb

input:

999900000

output:

311678722

result:

ok 1 number(s): "311678722"

Test #18:

score: 0
Accepted
time: 813ms
memory: 120656kb

input:

999000000

output:

60462624

result:

ok 1 number(s): "60462624"

Test #19:

score: 0
Accepted
time: 724ms
memory: 120656kb

input:

990000000

output:

444576800

result:

ok 1 number(s): "444576800"

Test #20:

score: 0
Accepted
time: 770ms
memory: 120736kb

input:

900000000

output:

95615129

result:

ok 1 number(s): "95615129"

Test #21:

score: 0
Accepted
time: 838ms
memory: 120656kb

input:

1361956

output:

813433539

result:

ok 1 number(s): "813433539"

Test #22:

score: 0
Accepted
time: 708ms
memory: 120712kb

input:

7579013

output:

677659797

result:

ok 1 number(s): "677659797"

Test #23:

score: 0
Accepted
time: 777ms
memory: 120684kb

input:

8145517

output:

801509527

result:

ok 1 number(s): "801509527"

Test #24:

score: 0
Accepted
time: 739ms
memory: 120724kb

input:

6140463

output:

869023935

result:

ok 1 number(s): "869023935"

Test #25:

score: 0
Accepted
time: 821ms
memory: 120680kb

input:

3515281

output:

989091505

result:

ok 1 number(s): "989091505"

Test #26:

score: 0
Accepted
time: 776ms
memory: 120772kb

input:

6969586

output:

539840131

result:

ok 1 number(s): "539840131"