Blum integer: Difference between revisions
Content added Content deleted
m (→{{header|C}}: Minor change.) |
(→{{header|C}}: Removed superfluous code.) |
||
Line 27: | Line 27: | ||
{{trans|Wren}} |
{{trans|Wren}} |
||
<syntaxhighlight lang="c">#include <stdio.h> |
<syntaxhighlight lang="c">#include <stdio.h> |
||
#include <stdbool.h> |
|||
#include <locale.h> |
#include <locale.h> |
||
bool isPrime(int n) { |
|||
if (n < 2) return false; |
|||
if (n%2 == 0) return n == 2; |
|||
if (n%3 == 0) return n == 3; |
|||
int d = 5; |
|||
while (d*d <= n) { |
|||
if (n%d == 0) return false; |
|||
d += 2; |
|||
if (n%d == 0) return false; |
|||
d += 4; |
|||
} |
|||
return true; |
|||
} |
|||
void primeFactors(int n, int *factors, int *length) { |
void primeFactors(int n, int *factors, int *length) { |
||
Line 79: | Line 64: | ||
int f[20], blum[50], counts[4] = {0}, digits[4] = {1, 3, 5, 7}; |
int f[20], blum[50], counts[4] = {0}, digits[4] = {1, 3, 5, 7}; |
||
setlocale(LC_NUMERIC, ""); |
setlocale(LC_NUMERIC, ""); |
||
while ( |
while (1) { |
||
primeFactors(i, f, &length); |
primeFactors(i, f, &length); |
||
if (length == 2 && f[0] != f[1] && f[0] % 4 == 3 && f[1] % 4 == 3) { |
if (length == 2 && f[0] != f[1] && f[0] % 4 == 3 && f[1] % 4 == 3) { |