#include <stdio.h>
#include <stdint.h>
#define MAX 50000
int prime(int32_t n);
int prime(int32_t n) {
int32_t i;
for (i= 2; i < n; i++)
if (n % i == 0)
return 0;
return 1;
}
int main() {
int32_t i;
for (i= 2; i <= MAX; i++) prime(i);
return 0;
}
int main() {
int i;
int n = 0;
for (i= 2; i <= MAX; i++) {
n += prime(i);
}
return n;
}
cython:
cdef int testp(int x):
cdef int i
for i in range(2, x):
if x % i == 0:
return 0
return 1
def runme():
cdef int i
cdef int n = 0
for i in range(1, 500000):
n += testp(i)
return n
numba:
import numba as nb
@nb.jit(nb.int32(nb.int32), nopython=True)
def testp(x):
for i in range(2, x):
if x % i == 0:
return 0
return 1
@nb.njit
def runme():
n = 0
for i in range(1, 500000):
n += testp(i)
return n
Julia:
function testp(x)
for i=2:x-1
x % Cint(i) == 0 && return 0
end
return 1
end
function runme()
for i = 1:500000
testp(Cint(i))
end
end