-
-
Save anonymous/ebc64d49abc5f1ee4e81 to your computer and use it in GitHub Desktop.
prime test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// compilation e.g. with gcc a.c -lm | |
#include "stdio.h" | |
#include "math.h" | |
#include "stdint.h" | |
#define true 1 | |
#define false 0 | |
#define bool int | |
typedef uint32_t u32; | |
int main () { | |
u32 nb = 1; | |
u32 nb_test = 2; | |
bool not_prime = true; | |
if ((nb % 2) == 0) { // If the number is even, add 1 to make it odd | |
nb++; | |
} | |
for (nb = nb; true; nb += 2) { | |
u32 square_root = sqrt(nb) + 1; | |
not_prime = true; | |
for (nb_test = 2; nb_test < square_root; nb_test++) { | |
if (nb % nb_test == 0) { | |
not_prime = false; | |
break; | |
} | |
} | |
if (not_prime) { | |
printf("%d\n", nb); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment