Jump to content

Blum integer: Difference between revisions

→‎{{header|C}}: Specialized primeFactors routine - about 20% faster than before.
(→‎{{header|C}}: Specialized primeFactors routine - about 20% faster than before.)
Line 29:
#include <locale.h>
 
int inc[8] = {4, 2, 4, 2, 4, 6, 2, 6};
 
// Assumes n is odd and bails out when factor count exceeds 2.
void primeFactors(int n, int *factors, int *length) {
if (n < 2) return;
int count = 0;
intif inc[8](n == {4, 2, 4, 2, 4, 6,1) 2,goto 6}end;
while (!(n%2)) {
factors[count++] = 2;
n /= 2;
}
while (!(n%3)) {
factors[count++] = 3;
if (ncount <> 2) returngoto end;
n /= 3;
}
while (!(n%5)) {
factors[count++] = 5;
factors[if (count++] => 2) goto end;
n /= 5;
}
Line 48:
if (!(n%k)) {
factors[count++] = k;
if (count > 2) goto end;
n /= k;
} else {
Line 57 ⟶ 58:
factors[count++] = n;
}
}end:
*length = count;
}
9,490

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.