Data update
This commit is contained in:
parent
35bcdeebf8
commit
74c69a0df6
2427 changed files with 31826 additions and 3468 deletions
62
Task/Sphenic-numbers/C-sharp/sphenic-numbers.cs
Normal file
62
Task/Sphenic-numbers/C-sharp/sphenic-numbers.cs
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using static System.Console;
|
||||
|
||||
public static class SphenicNumbers
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var numbers = FindSphenicNumbers(1_000_000).OrderBy(t => t.N).ToList();
|
||||
var triplets = numbers.Select(t => t.N).Consecutive().ToList();
|
||||
|
||||
WriteLine("Sphenic numbers up to 1 000");
|
||||
numbers.Select(t => t.N).TakeWhile(n => n < 1000).Chunk(15)
|
||||
.Select(row => row.Delimit()).ForEach(WriteLine);
|
||||
WriteLine();
|
||||
|
||||
WriteLine("Sphenic triplets up to 10 000");
|
||||
triplets.TakeWhile(n => n < 10_000).Select(n => (n-2, n-1, n)).Chunk(3)
|
||||
.Select(row => row.Delimit()).ForEach(WriteLine);
|
||||
WriteLine();
|
||||
|
||||
WriteLine($"Number of sphenic numbers < 1 000 000: {numbers.Count}");
|
||||
WriteLine($"Number of sphenic triplets < 1 000 000: {triplets.Count}");
|
||||
var (n, (a, b, c)) = numbers[199_999];
|
||||
WriteLine($"The 200 000th sphenic number: {n} = {a} * {b} * {c}");
|
||||
int t = triplets[4_999];
|
||||
WriteLine($"The 5 000th sphenic triplet: {(t-2, t-1, t)}");
|
||||
}
|
||||
|
||||
static IEnumerable<(int N, (int, int, int) Factors)> FindSphenicNumbers(int bound)
|
||||
{
|
||||
var primes = PrimeMath.Sieve(bound / 6).ToList();
|
||||
for (int i = 0; i < primes.Count; i++) {
|
||||
for (int j = i + 1; j < primes.Count; j++) {
|
||||
int p = primes[i] * primes[j];
|
||||
if (p >= bound) break;
|
||||
for (int k = j + 1; k < primes.Count; k++) {
|
||||
if (primes[k] > bound / p) break;
|
||||
int n = p * primes[k];
|
||||
yield return (n, (primes[i], primes[j], primes[k]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<int> Consecutive(this IEnumerable<int> source)
|
||||
{
|
||||
var (a, b, c) = (0, 0, 0);
|
||||
foreach (int d in source) {
|
||||
(a, b, c) = (b, c, d);
|
||||
if (b - a == 1 && c - b == 1) yield return c;
|
||||
}
|
||||
}
|
||||
|
||||
static string Delimit<T>(this IEnumerable<T> source, string separator = " ") =>
|
||||
string.Join(separator, source);
|
||||
|
||||
static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
|
||||
{
|
||||
foreach (T element in source) action(element);
|
||||
}
|
||||
}
|
||||
26
Task/Sphenic-numbers/Sidef/sphenic-numbers.sidef
Normal file
26
Task/Sphenic-numbers/Sidef/sphenic-numbers.sidef
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
func sphenic_numbers(upto) {
|
||||
3.squarefree_almost_primes(upto)
|
||||
}
|
||||
|
||||
func sphenic_triplets(upto) {
|
||||
var S = sphenic_numbers(upto)
|
||||
S.grep_kv {|k,v| v+2 == S[k+2] }.map{ [_, _+1, _+2] }
|
||||
}
|
||||
|
||||
with (1e3) {|n|
|
||||
say "Sphenic numbers less than #{n.commify}:"
|
||||
sphenic_numbers(n-1).slices(15).each{.map{'%4s' % _}.join.say}
|
||||
}
|
||||
|
||||
with (1e4) {|n|
|
||||
say "\nSphenic triplets less than #{n.commify}:"
|
||||
sphenic_triplets(n-1).each{.say}
|
||||
}
|
||||
|
||||
with (1e6) {|n|
|
||||
var triplets = sphenic_triplets(n-1)
|
||||
say "\nThere are #{3.squarefree_almost_prime_count(n-1)} sphenic numbers less than #{n.commify}."
|
||||
say "There are #{triplets.len} sphenic triplets less than #{n.commify}."
|
||||
with (2e5) {|n| say "The #{n.commify}th sphenic number is: #{nth_squarefree_almost_prime(n, 3)}." }
|
||||
with (5e3) {|n| say "The #{n.commify}th sphenic triplet is: #{triplets[n-1]}." }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue