Untitled

mail@pastecode.io avatar
unknown
csharp
a year ago
742 B
0
Indexable
Never
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;
    }
}