这是本蒟蒻第一次写题解。
先看数据范围:, 一看就要找规律!
直接开始打标找 的规律。
可以发现从 开始每个数字出现的次数为
于是题目就变成了求 这个序列前 的项和在加 。
因为 太大了所以要用分块的思想。
时间复杂度: 。
AC Code
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const LL mod = 998244353;
LL n, ans = 2, res = 0;
void work(){
LL num = 1, cnt = 1, tot = 1;
while(tot + 2 * cnt <= n){
num++, cnt *= 2, tot += cnt;
ans += ((num % mod) * (cnt % mod)) % mod;
}
ans += (((n - tot) % mod) * ((num + 1) % mod)) % mod;
ans %= mod;
}
int main(){
cin >> n;
n -= 1;
work();
cout << ((ans % mod) + (n % mod)) % mod << "\n";
return 0;
}最后总结一下这种题的思路:
如果 很大那么这题一定是找规律,先把 打表打出来再找规律。
记得点赞哦!
The End.
当我改完题解时这道题已经不在接受新题解了。。。