Blum integer: Difference between revisions
Content added Content deleted
(→{{header|Go}}: Oops!) |
(→{{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;
factors[count++] = 2;▼
}▼
while (!(n%3)) {
factors[count++] = 3;
n /= 3;
}
while (!(n%5)) {
factors[count++] = 5;
n /= 5;
}
Line 48:
if (!(n%k)) {
factors[count++] = k;
if (count > 2) goto end;
n /= k;
} else {
Line 57 ⟶ 58:
factors[count++] = n;
}
*length = count;
}
|