幸运数(基于素数筛)
代码如下
#include<bits/stdc++.h>
using namespace std;
const int N=110;
bool st[N];
int ans;
int main(){
int n;
cin >> n;
for(int i=1;i*6<=n; i++ ){
int t=0;
if(!st[i*6]){
st[i*6]=true;
t+=1;
}
if(!st[i*8]&&i*8<=n){
st[i*8]=true;
t+=1;
}
ans+=t;
}
cout << ans << endl;
return 0;
}
时间啊复杂度
还是线性时间复杂度,但稍微降低了一点