ruhan.habib39's blog

By ruhan.habib39, history, 9 years ago, In English

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]++;
     }
   }
}
  • Vote: I like it
  • -3
  • Vote: I do not like it

»
9 years ago, # |
  Vote: I like it +3 Vote: I do not like it
»
9 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

try to solve this.

This problem

»
9 years ago, # |
  Vote: I like it 0 Vote: I do not like it

It's called Prime Power Factorization(PPF).