Last active
June 12, 2017 22:35
-
-
Save Sam-Belliveau/4cde8126c30b1c5af10eea62d634395a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <conio.h> | |
#include <cmath> | |
using namespace std; | |
bool prime(unsigned long long int number){ | |
unsigned long long int limit = round(sqrt(number)); | |
unsigned long long int i = 3; | |
if (number%2 == 0 && number != 2){ | |
return false; | |
} | |
while (i <= limit){ | |
if (number%i == 0){ | |
return false; | |
} | |
i++; | |
i++; | |
} | |
return true; | |
} | |
int main(){ | |
unsigned long long int num = 3; | |
char Buffer[1024]; | |
unsigned long long int max = 184467440737095516131; | |
ofstream primes; | |
primes.rdbuf()->pubsetbuf(Buffer, 1024); | |
primes.open ("List of Prime Numbers Up To 18,446,744,073,709,551,615.txt"); | |
primes << "-----START-----\n2, "; | |
while (num <= max){ | |
if (prime(num)){ | |
primes << num << ", "; | |
} | |
num++; | |
if (num%1000000 == 0){ | |
cout << num/1000000 << " out of 18446744073710\n"; | |
} | |
num++; | |
} | |
primes << "\n-----END-----\n"; | |
primes.close(); | |
cout << "18446744073710 out of 18446744073710" << endl; | |
cout << "Done!"; | |
getch(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a program that I made that tests all of the prime numbers up to 18,446,744,073,709,551,615. When you download the .cpp file, you need to compile it in the most powerful compiler you got. I used a TDM-GCC compiler and got around 1,000,000 prime numbers a second for the first few numbers. The X out of 18446744073710 is telling you how many million numbers it has tested. This will obviously take a long time which is why I have taken this to GitHub. If anyone has the resources to do this quickly, I recommend you do this and share the results. WARNING: MY ESTIMATES FOR THE FINAL FILE SIZE IS 14000 PETABYTES!