Prime Factorization Algorithm

Revision en1, by ruhan.habib39, 2015-10-25 15:53:57

What's the name of the following algorithm:

const int MAXN = 100*1000;
unordered_map<int,int> factors[MAXN+10];
vector<bool> isprime(MAXN+10, true);
int primeFactor[MAXN+10];

void init() {
   isprime[0] = isprime[1] = false;
   for(int i = 2; i*i <= MAXN; i++) {
     if(isprime[i]) {
       for(int j = i*i; j <= MAXM; j += i) {
          isprime[j] = false;
          primeFactor[j] = i;
       }
     }
   }
   for(int i = 2; i <= MAXM; i++) {
     if(isprime[i]) factors[i][i] = 1;
     else {
       int dv = primeFactor[i];
       factors[i] = factors[i/dv];
       factors[i][dv]++;
     }
   }
}
Tags factorisation, prime-factorisation, algorithm, name

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ruhan.habib39 2015-10-25 15:53:57 677 Initial revision (published)