

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
Đáp án:
Giải thích các bước giải:
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+5;
bool prime[N];
void sieve(){
memset(prime,true,sizeof(prime));
prime[1]=prime[0]=false;
for(int i=1;i<=sqrt(N-5);i++){
if(prime[i]){
for(int j=i*i;j<=N-5;j+=i){
prime[j]=false;
}
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
sieve();
for(int i=1;i<=10;i++){
if(prime[i]){
cout<<i<<" ";
}
}
}Hãy giúp mọi người biết câu trả lời này thế nào?
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
vector<bool> xet(10000001,true);
xet[1]=false;
for(int i = 2; i*i <= 10000001; i++) {
if (xet[i]) {
for(int j = i*i; j <= 10000001; j+=i) {
xet[j] = false;
}
}
}
long long d=0, n,m;
cin>>n>>m;
for (int i=n;i<=m;i++) if (xet[i]==true) d++;
cout<<d;
}
Hãy giúp mọi người biết câu trả lời này thế nào?
Bảng tin