Blum integer: Difference between revisions
→{{header|C}}: Updated in line with Wren example - run time now under 1 second.
(→{{header|Wren}}: Optimized - about 30% faster than before.) |
(→{{header|C}}: Updated in line with Wren example - run time now under 1 second.) |
||
Line 27:
{{trans|Wren}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdbool.h>
#include <locale.h>
int inc[8] = {4, 2, 4, 2, 4, 6, 2, 6};
bool isPrime(int n) {
if (n%3 ==
while (d*d <= n) {
if (
▲ if (count > 2) goto end;
}
return true;
}
// Assumes n is odd.
int firstPrimeFactor(int n) {
if (n == 1) return 1;
if (!(n%3)) return 3;
if (!(n%5)) return 5;
for (int k = 7, i = 0; k*k <= n; ) {
if (!(n%k)) {
▲ if (count > 2) goto end;
n /= k;▼
} else {
k += inc[i];
Line 55 ⟶ 59:
}
}
}
int main() {
int i = 1, j, bc = 0,
int
setlocale(LC_NUMERIC, "");
while (
if (
printf("
if (!((j+1) % 10)) printf("\n");
} else if (bc ==
printf("
printf("
printf(" %6.3f%% end in %d\n", counts[j]/4000.0, digits[j]);
break;
}
▲ break;
}
}
}
i += (i % 5 == 3) ? 4 : 2;
}
return 0;
}</syntaxhighlight>
|