Untitled
unknown
csharp
2 years ago
742 B
3
Indexable
using System; using System.Threading.Tasks; class Program { static void Main(string[] args) { int start = 2; int end = 1000000; // use multiple threads to calculate prime numbers Parallel.For(start, end, i => { if (IsPrime(i)) { Console.WriteLine(i); } }); Console.WriteLine("Prime number calculation completed successfully."); Console.ReadLine(); } static bool IsPrime(int n) { if (n < 2) { return false; } for (int i = 2; i <= Math.Sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } }
Editor is loading...