while (PF*PF <= N) {
while (N%PF == 0) { N /= PF; factors.push_back(PF); }
PF = primes[++PF_idx];
}
This code might crash due to index-out-of-bound in PF = primes[++PF_idx]. Consider the case when PF_idx = primes.size()-1 (the last prime in primes), then when it goes to the problematic line, PF_idx becomes primes.size() which does not exist in PF.
This bug also happened in other functions as well, i.e., numPF(), numDiffPF(), sumPF(), numDiv(), sumDiv(), EulerPhi().
In
ch5/primes.cpp -- primeFactors(ll N)
:This code might crash due to index-out-of-bound in
PF = primes[++PF_idx]
. Consider the case whenPF_idx = primes.size()-1
(the last prime inprimes
), then when it goes to the problematic line,PF_idx
becomesprimes.size()
which does not exist inPF
.This bug also happened in other functions as well, i.e.,
numPF()
,numDiffPF()
,sumPF()
,numDiv()
,sumDiv()
,EulerPhi()
.