22 Star 152 Fork 69

编程语言算法集/C-Sharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
NumberOfPrimesByPowersOf10Sequence.cs 987 Bytes
一键复制 编辑 原始数据 按行查看 历史
namespace Algorithms.Sequences;
/// <summary>
/// <para>
/// Sequence of number of primes less than 10^n (with at most n digits).
/// </para>
/// <para>
/// Wikipedia: https://wikipedia.org/wiki/Prime-counting_function.
/// </para>
/// <para>
/// OEIS: https://oeis.org/A006880.
/// </para>
/// </summary>
public class NumberOfPrimesByPowersOf10Sequence : ISequence
{
/// <summary>
/// Gets sequence of numbers of primes.
/// </summary>
public IEnumerable<BigInteger> Sequence
{
get
{
ISequence primes = new PrimesSequence();
var powerOf10 = new BigInteger(1);
var counter = new BigInteger(0);
foreach (var p in primes.Sequence)
{
if (p > powerOf10)
{
yield return counter;
powerOf10 *= 10;
}
counter++;
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/TheAlgorithms/C-Sharp.git
git@gitee.com:TheAlgorithms/C-Sharp.git
TheAlgorithms
C-Sharp
C-Sharp
master

搜索帮助