#include<bits/stdc++.h>
using namespace std;
#define int __int128
signed main(){
signed M;
cin>>M;
int x=M;
for(int n=1;n<=x;n++){
if(sqrt(n*n*n*n*3.0/16.0-n*n*3.0/4.0)-(int)sqrt(n*n*n*n*3.0/16.0-n*n*3.0/4.0)<1e-10)cout<<(long long)n<<' ';
}
return 0;
}
:::
打表得到:
4 14 52 194 724 2702 10084 37634 140452
于是直接使用 OEIS 得到 A003500。
得到 a(n)=4a(n-1)-a(n-2) 的递推式。
直接计算即可。
:::success[关于复杂度]{open}
考虑 O(a(n))=x^n。
那么 x^n=4x^{n-1}-x^{n-2}。
所以 $O(a(n))=O\left(C_1(2+\sqrt3)^n+C_2(2-\sqrt3)^n\right)=O((2+\sqrt3)^n)$。
那么暴力计算 $a(n)$ 就是 $O(\log_{3.72}V)$。
我们直接预处理,可以这个复杂度做完。查询直接二分。$O(\log\log_{3.72}V)$。(注:这里为了突出增长速度,使用 $\log_{3.72}$ 而非 $\log$。)
:::
代码:
```cpp
#include<bits/stdc++.h>
using namespace std;
#define int __int128
const int maxn=453;
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#else
#define getchar _getchar_nolock
#define putchar _putchar_nolock
#endif
inline int read(){
int x=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
while (ch>='0'&&ch<='9'){x=(x<<1) + (x<<3)+ch-48;ch=getchar();}
return x*f;
}
inline void write(int x){
if(x<0){putchar('-');x=-x;}
if(x>9)write(x/10);
putchar(x%10+'0');
}
int a[maxn];
void init(){
a[0]=2;
a[1]=4;
for(int i=2;i<maxn;i++)a[i]=4*a[i-1]-a[i-2];
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
int T;
T=read();
init();
while(T--){
int n;
n=read();
write(*lower_bound(a+1,a+maxn-1,n));
putchar('\n');
}
return 0;
}
```