-
Notifications
You must be signed in to change notification settings - Fork 0
/
007.c
50 lines (41 loc) · 890 Bytes
/
007.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <limits.h>
#include <errno.h>
#define TRUE 1
#define FALSE 0
typedef unsigned char bool;
typedef long int32;
typedef long long int64;
typedef unsigned long uint32;
typedef unsigned long long uint64;
bool is_prime(uint64 value);
int main(int argc, char **argv)
{
uint64 current_value = 3;
uint64 primes_found = 2;
while (primes_found < 10001)
{
current_value += 2;
if (is_prime(current_value))
{
primes_found++;
}
}
printf("The 10001st prime is %llu.\n", current_value);
exit(EXIT_SUCCESS);
}
bool is_prime(uint64 value)
{
uint64 i, root_value_plus_one;
root_value_plus_one = ((uint64)sqrtl((long double)value)) + 1;
for (i = 2; i < root_value_plus_one; i++)
{
if (value % i == 0)
{
return FALSE;
}
}
return TRUE;
}