- Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathDivisorsCountSequence.cs
40 lines (37 loc) · 991 Bytes
/
DivisorsCountSequence.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
usingSystem.Collections.Generic;
usingSystem.Numerics;
namespaceAlgorithms.Sequences;
/// <summary>
/// <para>
/// Sequence of the number of divisors of n, starting with 1.
/// </para>
/// <para>
/// OEIS: https://oeis.org/A000005.
/// </para>
/// </summary>
publicclassDivisorsCountSequence:ISequence
{
/// <summary>
/// Gets sequence of number of divisors for n, starting at 1.
/// </summary>
publicIEnumerable<BigInteger>Sequence
{
get
{
yieldreturnBigInteger.One;
for(varn=newBigInteger(2);;n++)
{
varcount=2;
for(vark=2;k<n;k++)
{
BigInteger.DivRem(n,k,outvarremainder);
if(remainder==0)
{
count++;
}
}
yieldreturncount;
}
}
}
}