/ Published in: C#
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
static List<int> findPrimes(int max) { var maxSquareRoot = Math.Sqrt(max); vals.Add(2); for (int i = 3; i <= max; i += 2) { if (!eliminated[i]) { if (i < maxSquareRoot) { for (int j = i * i; j <= max; j += 2 * i) eliminated[j] = true; } vals.Add(i); } } return vals; }