-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
43 lines (38 loc) · 1.13 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System;
using System.Diagnostics;
namespace EratosthenesPrimes
{
class Program
{
static void Main(string[] args)
{
long limit = 1000;
int size = 1000;
if(args.Length >= 1)
{
if(!Int64.TryParse(args[0], out limit))
{
limit = 1000;
}
}
if(args.Length >= 2)
{
if(!Int32.TryParse(args[1], out size))
{
size = 1000;
}
}
var sw = new Stopwatch();
sw.Start();
var primes = Eratosthenes.FindPrimes(limit, size);
sw.Stop();
Console.WriteLine($"{primes.Count} primes found in {sw.Elapsed.Seconds}.{sw.ElapsedMilliseconds % 1000, 3:D3} seconds");
Console.WriteLine("Press Enter to print the primes or Ctrl-C to quit.");
Console.ReadLine();
foreach(var p in primes)
{
Console.WriteLine(p);
}
}
}
}