QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#138163#6740. FunctionNicolas125841ML 155ms790356kbC++171.4kb2023-08-11 02:26:322023-08-11 02:26:35

Judging History

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

  • [2023-08-11 02:26:35]
  • 评测
  • 测评结果:ML
  • 用时:155ms
  • 内存:790356kb
  • [2023-08-11 02:26:32]
  • 提交

answer

#include <bits/extc++.h>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define depref(x, y) (x[y] - x[y-1])

// To use most b i ts rather than jus t the lowest ones :
struct chash { // large odd number for C
    const uint64_t C = ll(4e18 * acos(0)) | 71;

    ll operator()(ll x) const { return __builtin_bswap64(x*C); }
};

__gnu_pbds::gp_hash_table<ll,ll,chash> s_f({},{},{},{},{1<<25});

const ll mod = 998244353;
const ll CAP = 20210926;
const ll DPC = 100000;

vector<ll> dp(DPC + 1, 0);

void prep(){
    dp[0] = 0;
    dp[1] = 1;

    for(int i = 2; i <= DPC; i++){
        for(int j = 1; j * j <= i; j++){
            if(i % j)
                continue;

            dp[i] += dp[i / j];

            if(j * j != i)
                dp[i] += dp[j];

            dp[i] %= mod;
        }
    }

    for(int i = 1; i <= DPC; i++)
        dp[i] = (dp[i] + dp[i - 1]) % mod;
}

ll solve(ll n){
    if(n <= DPC)
        return dp[n];
    
    if(s_f.find(n) != s_f.end())
        return s_f[n];
    
    ll ans = 0;
    for(ll i = 1, ub; i <= n; i = ub + 1){
        ub = n / (n / i);
        
        ans += solve(n/i) * (min(CAP, ub) - i + 1) % mod;
        ans %= mod;
    }

    return s_f[n] = ans;
}

int main(){
    ll n;
    cin >> n;

    prep();

    cout << solve(n) << "\n";
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 140ms
memory: 790176kb

input:

1

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 125ms
memory: 790164kb

input:

2

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 133ms
memory: 790068kb

input:

100

output:

949

result:

ok 1 number(s): "949"

Test #4:

score: 0
Accepted
time: 133ms
memory: 790356kb

input:

10

output:

19

result:

ok 1 number(s): "19"

Test #5:

score: 0
Accepted
time: 124ms
memory: 790136kb

input:

1000

output:

48614

result:

ok 1 number(s): "48614"

Test #6:

score: 0
Accepted
time: 155ms
memory: 790256kb

input:

10000

output:

2602393

result:

ok 1 number(s): "2602393"

Test #7:

score: 0
Accepted
time: 130ms
memory: 790220kb

input:

100000

output:

139804054

result:

ok 1 number(s): "139804054"

Test #8:

score: -100
Memory Limit Exceeded

input:

1000000

output:


result: