From bf2499ac3f67c67378d6f68ce06365efa6955810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20A=2E=20Ortega?= Date: Wed, 30 Nov 2016 15:15:52 +0100 Subject: [PATCH] Basic prime calculator. --- src/Main.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Main.cpp b/src/Main.cpp index 5b495fe..f0686e4 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1,6 +1,38 @@ #include +#include +#include + +static bool run; + +void leave(int signum); int main(void) { std::cout << "Indivisible v0.1\n"; + run = true; + + signal(SIGINT, leave); + + std::vector primes; + primes.push_back(2); + unsigned long long num = 2; + + while(run) { + bool isPrime = true; + for(auto i : primes) { + if(i > num / 2) break; + if(num % i == 0) isPrime = false; + } + if(isPrime) { + primes.push_back(num); + std::cout << num << std::endl; + } + ++num; + } + return 0; } + +void leave(int signum) { + std::cout << "Exiting (" << signum << ")\n"; + run = false; +}