diff options
Diffstat (limited to 'math/factor.cpp')
| -rw-r--r-- | math/factor.cpp | 34 |
1 files changed, 4 insertions, 30 deletions
diff --git a/math/factor.cpp b/math/factor.cpp index 43aeae3..0e5d7d8 100644 --- a/math/factor.cpp +++ b/math/factor.cpp @@ -1,27 +1,5 @@ -#include <iostream> -#include <vector> - -using namespace std; - -typedef unsigned long long ll; - const ll PRIME_SIZE = 10000000; -vector<int> primes; - -//Call before calculating anything -void primeSieve() { - vector<int> isPrime(PRIME_SIZE,true); - for(ll i = 2; i < PRIME_SIZE; i+=2) { - if(isPrime[i]) { - primes.push_back(i); - if(i*i <= PRIME_SIZE) { - for(ll j = i; i*j < PRIME_SIZE; j+=2) isPrime[i*j] = false; - } - } - if(i == 2) - i--; - } -} +vector<int> primes; //call primeSieve(PRIME_SIZE); before //Factorize the number n vector<int> factorize(ll n) { @@ -33,13 +11,9 @@ vector<int> factorize(ll n) { num /= primes[pos]; factor.push_back(primes[pos]); } - else - pos++; - if(primes[pos]*primes[pos] > n) - break; + else pos++; + if(primes[pos]*primes[pos] > n) break; } - if(num != 1) - factor.push_back(num); + if(num != 1) factor.push_back(num); return factor; - } |
