Uses unsigned long long, goes up to ULONG_LONG_MAX.

Intel Core Duo 2 processor, running Cygwin on Windows XP, and compiled using gcc 3.4.4. Stops at first million results due to time. Can reasonably get to 10 million, if you’re willing to wait.

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

int main(int argc, char **argv){    unsigned long long divisor, max_divisor, prime_test;    int break_time = 0;

    printf("%llu\n", 2LL);    for(prime_test = 3LL; prime_test < ULONG_LONG_MAX; prime_test+=2LL)    {        max_divisor=1LL+sqrt(prime_test);        for(divisor=3LL;divisor <= max_divisor; divisor+=2LL)        {            if(prime_test % divisor == 0)            {                break;            }        }        if(divisor >= max_divisor)        {            printf("%llu\n", prime_test);        }        else        {            continue;        }        break_time++;        if(break_time == 999999)        {            break;        }    }    return 0;}
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • StumbleUpon
  • Tumblr
  • TwitThis
  • FriendFeed
  • Netvibes
  • Ping.fm
  • Posterous
  • Technorati
  • Tipd
  • Twitter
  • Yahoo! Buzz