题解:P11397 界分数
PrinceEvan · · 题解
这是本蒟蒻写的第一篇题解,也是第一道场切的绿题,当时交不了题解了,现在发现又能交了,希望管理员给个通过。
思路:
先看数据范围:
直接开始打标找
容易发现这个序列中
优化:
因为
时间复杂度:
代码:
#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;
}