Testing testing one two 3
This commit is contained in:
commit
b668ce7f8a
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Ignore emacs backups
|
||||
*~
|
28
main.cpp
Normal file
28
main.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
// Generate primes using the sieve of eratosthenes
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
// TODO: make it work with GMP (https://gmplib.org/)
|
||||
unsigned int nextnumber { 3 };
|
||||
bool notprime;
|
||||
std::vector<unsigned int> primes;
|
||||
primes.push_back(2); // Initial prime
|
||||
std::cout << "2\n";
|
||||
|
||||
while (true) {
|
||||
notprime = false;
|
||||
for (unsigned int i=0;i<primes.size();++i) {
|
||||
if (nextnumber % primes[i] == 0) {
|
||||
notprime = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!notprime) {
|
||||
primes.push_back(nextnumber);
|
||||
std::cout << nextnumber << '\n';
|
||||
}
|
||||
nextnumber += 2; // Except for two, primes are odd. This skips even numbers.
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user