Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 65 lines (61 sloc) 1.427 kb
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
// Main.cs created with MonoDevelop
// User: steven at 04:10 11/11/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using System.Diagnostics;

namespace GenPrime
{
class GenPrime
{
private static bool isprime(ulong x)
{
ulong lim, y;
if (x < 2)
return false;
if (x == 2)
return true;
if (x % 2 == 0)
return false;
if (x < 9)
return true;
if ((x + 1) % 6 != 0)
if ((x - 1) % 6 != 0)
return false;
lim = (ulong)(Math.Sqrt((double)x) + 1.0f);
for (y = 3; y < lim; y += 2)
{
if (x % y == 0)
return false;
}
return true;
}

private static ulong genprime(ulong max)
{
ulong count = 0,
current = 1;
while (count < max)
{
if (isprime(current))
count++;
current++;
}
return current - 1;
}

public static void Main(string[] args)
{
ulong start = ulong.Parse(args[0]), stop = ulong.Parse(args[1]) + 1, last;
Stopwatch sw = new Stopwatch();
for ( ulong x = start; x < stop; x += start )
{
sw.Start();
last = genprime(x);
sw.Stop();
double duration = (double)sw.ElapsedTicks / (double)Stopwatch.Frequency;
Console.WriteLine( "Found {0,8} primes in {1,10:0.00000} seconds (last was {2,10})",
x, duration, last);
}
}
}
}
Something went wrong with that request. Please try again.