Strong and weak primes: Difference between revisions

Added C# implementation
(Added C# implementation)
Line 140:
weak primes below 10,000,000: 321,750
</pre>
 
=={{header|C sharp}}==
{{works with|C sharp|7}}
<lang csharp>using static System.Console;
using static System.Linq.Enumerable;
using System;
 
public static class StrongAndWeakPrimes
{
public static void Main() {
var primes = PrimeGenerator(10_000_100).ToList();
var strongPrimes = from i in Range(1, primes.Count - 2) where primes[i] > (primes[i-1] + primes[i+1]) / 2 select primes[i];
var weakPrimes = from i in Range(1, primes.Count - 2) where primes[i] < (primes[i-1] + primes[i+1]) / 2 select primes[i];
WriteLine($"First 36 strong primes: {string.Join(", ", strongPrimes.Take(36))}");
WriteLine($"There are {strongPrimes.TakeWhile(p => p < 1_000_000).Count():N0} strong primes below {1_000_000:N0}");
WriteLine($"There are {strongPrimes.TakeWhile(p => p < 10_000_000).Count():N0} strong primes below {10_000_000:N0}");
WriteLine($"First 37 weak primes: {string.Join(", ", weakPrimes.Take(37))}");
WriteLine($"There are {weakPrimes.TakeWhile(p => p < 1_000_000).Count():N0} weak primes below {1_000_000:N0}");
WriteLine($"There are {weakPrimes.TakeWhile(p => p < 10_000_000).Count():N0} weak primes below {1_000_000:N0}");
}
}</lang>
{{out}}
<pre>
First 36 strong primes: 11, 17, 29, 37, 41, 59, 67, 71, 79, 97, 101, 107, 127, 137, 149, 163, 179, 191, 197, 223, 227, 239, 251, 269, 277, 281, 307, 311, 331, 347, 367, 379, 397, 419, 431, 439
There are 37,723 strong primes below 1,000,000
There are 320,991 strong primes below 10,000,000
First 37 weak primes: 7, 13, 19, 23, 31, 43, 47, 61, 73, 83, 89, 103, 109, 113, 131, 139, 151, 167, 181, 193, 199, 229, 233, 241, 271, 283, 293, 313, 317, 337, 349, 353, 359, 383, 389, 401, 409
There are 37,779 strong primes below 1,000,000
There are 321,749 strong primes below 1,000,000</pre>
 
=={{header|Go}}==
196

edits