题意
找到区间 中有多少个数 。
分析
这道题数据较大,,所以不可以对于区间中每个数检查是否满足条件。
注意到区间开始位置确定为 ,也就是说所有 的正整数都可以被包含,我们就可以先确定 ,再找当前所有满足 的 。由于 ,所以对于 最多只需要枚举 次即可。此时可以暴力枚举 ,范围是 ,时间复杂度也不大,因此这种方法是可行的。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, ans;
signed main(){
cin >> n;
int a = 2;
while (a <= n){
int b = 1;
while (a * b * b <= n){
ans++;
b += 2;
}
a *= 2;
}
cout << ans;
return 0;
}