namespace tasks; public static class PrimeFinder { public static IEnumerable SieveOfEratosthenes(int upperBound) { if (upperBound < 2) yield break; var isComposite = new bool[upperBound + 1]; for (var i = 2; i <= upperBound; i++) { if (isComposite[i]) continue; yield return i; for (var j = i * 2; j <= upperBound; j += i) { isComposite[j] = true; } } } }