题意
定义
\[
f(n)=\left\{
\begin{array}{}
1 & n=1\\
f(n-f(f(n-1)))+1 & n>1
\end{array}
\right.
\]
\(g(n)\) 为满足\(f(m) = n\)的最大的\(m\)。
给出\(n\),求\(g(n) \mod 998244353\),和\(g(g(n)) \mod 998244353\)。
对100%的数据,\(n \leq 10^9\)
分析
代码
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#pragma GCC optimize ("O0")
using namespace std;
template<class T> inline T read(T&x)
{
T data=0;
int w=1;
char ch=getchar();
while(!isdigit(ch))
{
if(ch=='-')
w=-1;
ch=getchar();
}
while(isdigit(ch))
data=10*data+ch-'0',ch=getchar();
return x=data*w;
}
typedef long long ll;
const int INF=0x7fffffff;
const ll MAXN=1e6+7,lim=1e6,mod=998244353;
ll f[MAXN]={3,1,2,2};
ll ans1=5,ans2=11;
ll n;
int main()
{
// freopen("recursion.in","r",stdin);
// freopen("recursion.out","w",stdout);
read(n);
if(n==1)
{
puts("1 1");
return 0;
}
if(n==2)
{
puts("3 5");
return 0;
}
for(int i=3;i<=lim;++i)
{
for(int j=f[0]+1;j<=min(lim,f[0]+f[i]);++j)
f[j]=i;
ll up=min(f[i]+f[0],n),down=f[0]+1;
if(down>n)
break;
(ans1 += (ll)(up - down + 1) * i)%=mod;
if((up + down)&1)
{
(ans2 += (up + down) % mod * (up - down + 1)/2 % mod * i) %= mod;
}
else
{
(ans2 += (up + down)/2 % mod * (up - down + 1) % mod * i) %= mod;
}
f[0]+=f[i];
}
printf("%lld %lld\n",ans1,ans2);
// fclose(stdin);
// fclose(stdout);
return 0;
}