Skip to content

Instantly share code, notes, and snippets.

@hnw
Created January 2, 2014 05:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnw/8215384 to your computer and use it in GitHub Desktop.
Save hnw/8215384 to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Collections.Generic;
class Prime
{
private static List<int> odd_primes = new List<int>();
private static bool IsPrime(int val)
{
foreach (var i in odd_primes)
{
if (i*i > val)
{
break;
}
if (val % i == 0)
{
return false;
}
}
return true;
}
public static IEnumerable<int> seq()
{
yield return 2;
for (var i = 3; ; i += 2)
{
if (IsPrime(i))
{
odd_primes.Add(i);
yield return i;
}
}
}
}
class Prob7
{
static void Main()
{
Console.WriteLine(Prime.seq().Skip(10000).First());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment