【[ABC414E] Count A%B=C】题解
Pig_Eat_Earth · · 题解
思路
先分析条件。
-
a\bmod b=c 一个
a 和一个b 对应一个c 。 -
1\le a,b,c\le N 限定了
a,b,c 的范围,以及b\nmid a 。 -
限定了 $a>b$。
考虑一个
则答案为:
前一项可以
注意事项
- 十年 OI 一场空,不开 __ 见祖宗;
- 模意义下的除法用逆元。
AC Code
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353, I = 499122177;
// I 为 2 模 998244353 意义下的逆元。
ll n, ans;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
ll l = 1, r = 0;
for(; l <= n; l = r + 1){
r = n / (n / l);
ans -= ((r - l + 1) % MOD) * ((n / l) % MOD) % MOD;
ans = (ans % MOD + MOD) % MOD;
} // 数论分块
n %= MOD;
ans += (((n * n % MOD) + n) % MOD) * I % MOD;
ans %= MOD;
cout << ans;
}