C# port of prime (http://failedxyz.github.io/prime)