This commit is contained in:
Zengtudor 2024-12-29 11:14:21 +08:00
parent 9400bf480d
commit 8875d07b8f
2 changed files with 51 additions and 1 deletions

51
src/12/c14/c14_lv255.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <cstddef>
#include <iostream>
#include <ostream>
#include <vector>
using namespace std;
template<class T>
ostream&operator<<(ostream &os,vector<T> const& v){
os<<"{ ";
if(v.size()==0){
os<<" }";
}else{
for(size_t i=0;i<v.size()-1;i++){
os<<v[i]<<" ,";
}
os<<v[v.size()-1]<<" }";
}
return os;
}
vector<int> getPrimes(int const& end){
vector<bool> isFactor(end+1,false);
for(int i=2;i<end;i++){
if(isFactor[i]==false){
for(int j=i+i;j<end;j+=i){
isFactor[j]=true;
}
}
}
vector<int> primes;
for(int i=2;i<end;i++){
if(isFactor[i]==false){
// cout<<i<<' ';
primes.push_back(i);
}
}
return primes;
}
int main(){
// const auto primes255 = getPrimes(2500+1);
vector<int> nums(5,0);
for(auto const& i:getPrimes(1e5)){
nums[i%5]++;
}
for(int i=0;i<5;i++){
cout<<i<<" : "<<nums[i]<<'\n';
}
cout<<'\n';
}

View File

@ -1,7 +1,6 @@
#include <cstddef> #include <cstddef>
#include <iostream> #include <iostream>
#include <ostream> #include <ostream>
#include <type_traits>
#include <vector> #include <vector>
using namespace std; using namespace std;