#include #include #include #include using namespace std; #define N_MAXPRIMES 10000000 #define N_MAXFACTORS 128 int main(int argc, char *argv[]) { signed long n = atoi(argv[1]); cout << n << endl; vector primes; primes.resize(N_MAXPRIMES); long factors[N_MAXFACTORS]; ifstream Primes("primes_up_to_10m.txt"); int i; int temp; for(i=0;i<=N_MAXPRIMES;i++) { Primes >> temp; //cout << temp << endl; primes[i] = temp; } i=0; /*while(i<=N_MAXPRIMES) { cout << primes[i] << endl; i++; }*/ int sqrtn = sqrt(n)+1; int factnum = 0; while(primes[i]<=sqrtn) { if(n % primes[i] == 0) { factors[factnum] = primes[i]; cout << "Factored by " << primes[i] << " == " << factors[factnum] << endl; factnum++; } i++; } i = 0; if(factnum != 0) { factnum--; for(i=0;i<=factnum;i++) { cout << factors[i] << " "; } } else { cout << n << " is prime." << endl; } cout << endl; return 1; }