1
0
Fork 0

problem 10 done, and problem 7 rewritten (new is_prime algorithm)

This commit is contained in:
Henrik Hautakoski 2010-04-09 16:20:42 +02:00
parent 8498165fef
commit 2ba8a8aaeb
4 changed files with 64 additions and 36 deletions

18
lib/prime.c Normal file
View 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;
}

10
lib/prime.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef __PRIME_H
#define __PRIME_H
#include <stdint.h>
int is_prime(uint32_t p);
#endif /* __PRIME_H */