Anti-primes: Difference between revisions
Content deleted Content added
add PicoLisp |
Added C# |
||
Line 215:
The first 20 anti-primes are:
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
=={{header|C sharp}}==
{{works with|C sharp|7}}
<lang csharp>using System;
using System.Linq;
using System.Collections.Generic;
public static class Program
{
public static void Main() =>
Console.WriteLine(string.Join(" ", FindAntiPrimes().Take(20)));
static IEnumerable<int> FindAntiPrimes() {
int max = 0;
for (int i = 1; ; i++) {
int divisors = CountDivisors(i);
if (divisors > max) {
max = divisors;
yield return i;
}
}
int CountDivisors(int n) => Enumerable.Range(1, n / 2).Count(i => n % i == 0) + 1;
}
}</lang>
{{out}}
<pre>
1 2 4 6 12 24 36 48 60 120 180 240 360 720 840 1260 1680 2520 5040 7560
</pre>
|