Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Prime-conspiracy/C-sharp/prime-conspiracy.cs
Normal file
47
Task/Prime-conspiracy/C-sharp/prime-conspiracy.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
|
||||
namespace PrimeConspiracy {
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
const int limit = 1_000_000;
|
||||
const int sieveLimit = 15_500_000;
|
||||
|
||||
int[,] buckets = new int[10, 10];
|
||||
int prevDigit = 2;
|
||||
bool[] notPrime = Sieve(sieveLimit);
|
||||
|
||||
for (int n = 3, primeCount = 1; primeCount < limit; n++) {
|
||||
if (notPrime[n]) continue;
|
||||
|
||||
int digit = n % 10;
|
||||
buckets[prevDigit, digit]++;
|
||||
prevDigit = digit;
|
||||
primeCount++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
if (buckets[i, j] != 0) {
|
||||
Console.WriteLine("{0} -> {1} count: {2,5:d} frequency : {3,6:0.00%}", i, j, buckets[i, j], 1.0 * buckets[i, j] / limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static bool[] Sieve(int limit) {
|
||||
bool[] composite = new bool[limit];
|
||||
composite[0] = composite[1] = true;
|
||||
|
||||
int max = (int)Math.Sqrt(limit);
|
||||
for (int n = 2; n <= max; n++) {
|
||||
if (!composite[n]) {
|
||||
for (int k = n * n; k < limit; k += n) {
|
||||
composite[k] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return composite;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue