problem 10 done, and problem 7 rewritten (new is_prime algorithm)
This commit is contained in:
parent
8498165fef
commit
2ba8a8aaeb
4 changed files with 64 additions and 36 deletions
18
lib/prime.c
Normal file
18
lib/prime.c
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
|
||||
#include "prime.h"
|
||||
#include <math.h>
|
||||
|
||||
int is_prime(uint32_t p) {
|
||||
|
||||
uint32_t i, l;
|
||||
|
||||
if (p < 2 || (p & 1) == 0)
|
||||
return 0;
|
||||
|
||||
l = ((uint32_t)sqrt(p)) + 1;
|
||||
|
||||
for(i=3; i < l; i+=2)
|
||||
if (p % i == 0) return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue