-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy path2.cs
More file actions
33 lines (31 loc) · 739 Bytes
/
2.cs
File metadata and controls
33 lines (31 loc) · 739 Bytes
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
using System;
using System.Collections;
using System.IO;
internal static class Program
{
public static void Main(string[] args)
{
var n = args.Length > 0 ? int.Parse(args[0]) : 4;
for (var i = 0; i < 3; i++)
{
Sieve(10000 << (n - i));
}
}
private static void Sieve(int n)
{
var flags = new BitArray(n, false);
var count = 0;
for (var i = 2; i < n; i++)
{
if (!flags[i])
{
count += 1;
for (var j = i << 1; j < n; j += i)
{
flags[j] = true;
}
}
}
Console.WriteLine($"Primes up to {n,8} {count,8}");
}
}