All pastes #569103 Raw Edit

Miscellany

public cpp v1 · immutable
·published 2007-06-16 00:26 UTC
rendered paste body
#include <iostream>#include <math.h>#include <fstream>#include <vector>using namespace std;#define N_MAXPRIMES 10000000#define N_MAXFACTORS 128int main(int argc, char *argv[]) {        signed long n = atoi(argv[1]);        cout << n << endl;        vector<signed int> 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;}