public static List<string> findPrimes(long max) { //var vallist= new List<List<string>>((int)Math.Ceiling(max/(double)Int32.MaxValue)); //for(int i = 0;i<(int)Math.Ceiling(max/(double)Int32.MaxValue);i++){ // int length = i==(int)Math.Ceiling(max/(double)Int32.MaxValue)-1?(int)(max/(Math.Log(max)-//1.08366)):Int32.MaxValue; //vallist.Add(new List<string>(length)); //} var vals = new List<string>((int)(max/(Math.Log(max)-1.08366))); long maxSquareRoot = (long)Math.Sqrt(max); LongBitArray eliminated = new LongBitArray(max + 1); //long primeAmount=0; //yield return 2; //vallist[0].Add(2.ToString()); vals.Add(2.ToString()); for (long i = 3; i <= max; i+=2) { if (!eliminated[i]) { if (i < maxSquareRoot) { for (long j = i * i; j <= max; j+=2*i) eliminated[j] = true; } //Console.WriteLine(i); //yield return i; //vallist[(int)Math.Floor(primeAmount/(double)Int32.MaxValue)].Add(i.ToString()); //primeAmount++; vals.Add(i.ToString()); } } return vals; }
public static void Main(string[] args) { LongBitArray test = new LongBitArray((long)Int32.MaxValue+50); test[30] = true; test[31] = true; Console.WriteLine(test[30] + " " + test[31]); //test[BigInteger.Parse("9223372036854775810") + 30] = false; //test[BigInteger.Parse("9223372036854775810") + 31] = true; test[(long)Int32.MaxValue + 30] = false; test[(long)Int32.MaxValue + 31] = true; Console.WriteLine(test[(long)Int32.MaxValue + 30] + " " + test[(long)Int32.MaxValue + 31]); Console.ReadLine(); }
public static IEnumerable<long> findPrimesEnum(long max) { //var vals = new List<long>((int)(max/(Math.Log(max)-1.08366))); long maxSquareRoot = (long)Math.Sqrt(max); LongBitArray eliminated = new LongBitArray(max + 1); yield return 2; //vals.Add(2); for (long i = 3; i <= max; i += 2) { if (!eliminated[i]) { if (i < maxSquareRoot) { for (long j = i * i; j <= max; j += 2 * i) eliminated[j] = true; } //Console.WriteLine(i); yield return i; //vals.Add(i); } } //return vals; }
public static IEnumerable<long> Sund(long n) { yield return 2; long totalCount = 0; long k = n / 2; LongBitArray myBA1 = new LongBitArray((long)(k + 1)); /* SET ALL TO PRIME STATUS */ //myBA1.SetAll(true); /* SEIVE */ long maxVal = 0; long denominator = 0; for (long i = 1; i < k; i++) { if (i % 1 == 0) { Console.WriteLine("Cuz baby now we got baaaaad blood " + i); } denominator = (i << 1) + 1; maxVal = (k - i) / denominator; for (long j = i; j <= maxVal; j++) { myBA1[i + j * denominator] = false; // if ((i + j * denominator) > (long)Int32.MaxValue*2) { Console.WriteLine(i + j * denominator); } } } long prime = 0; for (long i = 1; i < k; i++) { if (myBA1[i]) { //Console.WriteLine(i); totalCount++; prime = (i << 1) + 1; yield return prime; } } }