Skip to content

Commit 03e6641

Browse files
authored
Add A057588 Kummer Numbers sequence (TheAlgorithms#296)
1 parent 1c465ec commit 03e6641

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Linq;
2+
using System.Numerics;
3+
using Algorithms.Sequences;
4+
using FluentAssertions;
5+
using NUnit.Framework;
6+
7+
namespace Algorithms.Tests.Sequences
8+
{
9+
public class KummerNumbersSequenceTests
10+
{
11+
[Test]
12+
public void First10ElementsCorrect()
13+
{
14+
var sequence = new KummerNumbersSequence().Sequence.Take(10);
15+
sequence.SequenceEqual(new BigInteger[]
16+
{ 1, 5, 29, 209, 2309, 30029, 510509, 9699689, 223092869, 6469693229 })
17+
.Should().BeTrue();
18+
}
19+
}
20+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using System.Numerics;
4+
5+
namespace Algorithms.Sequences
6+
{
7+
/// <summary>
8+
/// <para>
9+
/// Sequence of Kummer numbers (also called Euclid numbers of the second kind):
10+
/// -1 + product of first n consecutive primes.
11+
/// </para>
12+
/// <para>
13+
/// Wikipedia: https://wikipedia.org/wiki/Euclid_number.
14+
/// </para>
15+
/// <para>
16+
/// OEIS: https://oeis.org/A057588.
17+
/// </para>
18+
/// </summary>
19+
public class KummerNumbersSequence : ISequence
20+
{
21+
/// <summary>
22+
/// Gets sequence of Kummer numbers.
23+
/// </summary>
24+
public IEnumerable<BigInteger> Sequence
25+
{
26+
get
27+
{
28+
var primorialNumbers = new PrimorialNumbersSequence().Sequence.Skip(1);
29+
30+
foreach (var n in primorialNumbers)
31+
{
32+
yield return n - 1;
33+
}
34+
}
35+
}
36+
}
37+
}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ This repository contains algorithms and data structures implemented in C# for ed
119119
* [A007318 Binomial](./Algorithms/Sequences/BinomialSequence.cs)
120120
* [A010051 Binary Prime Constant](./Algorithms/Sequences/BinaryPrimeConstantSequence.cs)
121121
* [A011557 Powers of 10](./Algorithms/Sequences/PowersOf10Sequence.cs)
122+
* [A057588 Kummer Numbers](./Algorithms/Sequences/KummerNumbersSequence.cs)
122123
* [A019434 Fermat Primes](./Algorithms/Sequences/FermatPrimesSequence.cs)
123124
* [A181391 Van Eck's](./Algorithms/Sequences/VanEcksSequence.cs)
124125
* [String](./Algorithms/Strings)

0 commit comments

Comments
 (0)