题目解法
- 数学。
解题思路
设 (因为太长了我不想抄)。若对于一个数 满足 ,则有 。反过来,若 ,那么 。
使用一个 while 循环,定义一个计数器变量 与答案变量 (初始值均为 ),按顺序做如下操作,直到 :
- 将 减去 ;
- 将 加上 ;
- 将 加上 。
最后输出 即可。
AC 代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD=998244353;
ll n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n;
if(n>=MOD){
int k=0;
ll ans=0;
while(n>=MOD){
n-=MOD;
ans+=k*MOD;
k++;
ans%=MOD;
}
ans+=(n+1)*k;
ans%=MOD;
cout<<ans<<endl;
}else{
cout<<0<<endl;
}
return 0;
}