题目
样例
Input
10
10
100
1000
10000
100000
114514
1919810
20190104
123123123123
10000001000000
Output
2
5
14
31
65
67
158
326
5226
22091
分析
因为是 k^3,所以 k 最大是 1e5,枚举 k ,递推出所有解,统统塞到一个 vector 里面,然后每次询问二分找一下位置就行了。
代码
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000000000000ll
vector<long long> ans{1};
int main()
{
__int128 x,y,tmp;
for (long long i=2; i<=1000000; i++) {
x=i;
y=i*i*i;
while (y<=INF) {
ans.push_back(y);
tmp=y;
y=i*i*y-x;
x=tmp;
}
}
sort(ans.begin(),ans.end());
int ttt;
long long cnt,n;
scanf("%d",&ttt);
while (ttt--) {
scanf("%lld",&n);
cnt=upper_bound(ans.begin(),ans.end(),n)-ans.begin();
printf("%lld\n",cnt);
}
return 0;
}