数论之分块

【数论】数论分块(详细,小白):余数求和&&约数研究

数论分块 - OI Wiki (oi-wiki.org)

一道例题

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

const LL mod = 998244353;
//题目特殊,需要开int_128
//比赛和oj一般不能开int_128
int main()
{
    __int128 res;
    LL n;
    cin >> n;
    res = (__int128)n * n;
    for(__int128 i = 1, j; i <= n; i = j + 1)
    {
        j = n / (n / i);
        res -= (n / i) * (j - i + 1) * (i + j) / 2;
    }
    cout << (long long)((res % mod + mod) % mod) << endl;    
    
    return 0;
}

posted @ 2022-05-05 08:41  光風霽月  阅读(13)  评论(0编辑  收藏  举报