Optimized prime number generator

Same specs as previous system, 8 hours to find all primes to ULONG_MAX.


#include <stdio.h>
#include <malloc.h>
#include <limits.h>
#include <math.h>

struct linked_list
{
unsigned long number;
struct linked_list *next;
};

int main(int argc, char **argv)
{
unsigned long divisor, max_divisor, prime_test;
unsigned long max_prime_to_store;
struct linked_list *first=NULL, *current=NULL, *last=NULL;

first=(struct linked_list *)malloc(sizeof(struct linked_list));
first->number = 2L;
first->next = NULL;
last = first;
printf("%lun", 2L);

max_prime_to_store = 1L + sqrt(ULONG_MAX);

for(prime_test = 3L; prime_test < ULONG_MAX; prime_test+=2L)
{
max_divisor=1L+sqrt(prime_test);
for(current = first; current && current->number <= max_divisor; current = current->next)
{
if(prime_test % current->number == 0)
{
break;
}
}
if(!current || current->number > max_divisor)
{
if(prime_test <= max_prime_to_store)
{
last->next = (struct linked_list *)malloc(sizeof(struct linked_list));
last = last->next;
last->next = NULL;
last->number = prime_test;
}
printf("%lun", prime_test);
}
}
return 0;
}