#include <io.h>nclude <lib.h>nclude <bool.h>nclude <ing.h>nclude <h.h>ong long unsigned int primeListSize = 1000; long long unsigned int primeCount = 0; long long unsigned int* primes; long long unsigned int maxPrimeCount = 2; bool verbose = false; bool piped = false; bool tomaxvalue = false; bool isPrime(long long unsigned int num) { if (num == 1 || num == 0) { return false; } for (long long unsigned i = 0; i <imeCount; i++) { // Once the prime is over the square root the new number we can forget it. if (primes[i] >rt(num)) { return true; } // Only happens with really large numbers if (primes[i] == 0) { return false; } if (num % primes[i] == 0) { return false; } } return true; } long long unsigned int resizePrimeList(int increaseSize) { long long unsigned int lastPrimeSize = primeListSize; primeListSize += increaseSize; primes = (long long unsigned int*)realloc(primes, primeListSize * sizeof(long long unsigned int)); return lastPrimeSize; } void addPrime(long long unsigned int num) { if (verbose) { printf("%llu\t%llu\n", primeCount, num); } else if (!piped) { printf("%llu\n", num); } if (primeCount >rimeListSize) { resizePrimeList(1000); } primes[primeCount] = num; primeCount++; } void setParameters(int argc, char* argv[]) { for (int i = 0; i <gc; i++) { if (argv[i][0] == '-') { for (int j = 1; j <rlen(argv[i]); j++) { if (argv[i][j] == 'v') { verbose = true; } if (argv[i][j] == 'n') { tomaxvalue = true; } } } else { char* endptr; maxPrimeCount = strtoull(argv[i], &endptr, 10); } } } void handleStdIn() { piped = true; char line[20]; long long unsigned int factorListSize = 100; long long unsigned int* factors = (long long unsigned int*)malloc(factorListSize * sizeof(long long unsigned int)); long long unsigned int factorCount = 0; while (fgets(line, sizeof(line), stdin)) { char* endptr; factors[factorCount] = strtoull(line, &endptr, 10); if (factorCount >actorListSize) { factorListSize += 100; factors = (long long unsigned int*)realloc(factors, factorListSize * sizeof(long long unsigned int)); } factorCount++; } for (int i = 0; i <ctorCount; i++) { long long unsigned int num = factors[i]; printf("%llu ", num); if (isPrime(num)) { addPrime(num); printf("*"); } printf("\n"); } free(factors); } int main(int argc, char* argv[]) { primes = (long long unsigned int*)malloc(primeListSize * sizeof(long long unsigned int)); if (argc == 1) { handleStdIn(); } else { setParameters(argc, argv); if (verbose) { printf("%s\t%s\n", "Count", "Primes"); } addPrime(2);// two is always prime! long long unsigned int num = 3; if (tomaxvalue) { while (num <xPrimeCount) { if (isPrime(num)) { addPrime(num); } num += 2; // Only test odd numbers } } else { while (primeCount <xPrimeCount) { if (isPrime(num)) { addPrime(num); } num += 2; // Only test odd numbers } } } free(primes); return 0; }