LuoguU11474 - [Snakes Round 2] Calculating

2017/10/25

题目

若 x 分解质因数结果为

解法

除法分块。

代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MOD = 998244353;

LL sol(LL t) {
    LL ret = 0;
    
    for(LL i=1, lst=0;i<=t;i=lst+1) {
        lst = min(t, t / (t / i));
        ret = (ret + ((t / i) % MOD) * (lst - i + 1)) % MOD;
    }
    
    return ret;
}

int main() {
    LL l, r;
    
    scanf("%lld %lld", &l, &r);
    
    printf("%lld\n", (sol(r) - sol(l-1) + MOD) % MOD);
}