18 Star 133 Fork 63

编程语言算法集 / C-Sharp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
NumberOfPrimesByNumberOfDigitsSequence.cs 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
Gerson Jr 提交于 2024-01-03 22:51 . Switch to file-scoped namespaces (#432)
using System.Collections.Generic;
using System.Numerics;
namespace Algorithms.Sequences;
/// <summary>
/// <para>
/// Number of primes with n digits
/// (The number of primes between 10^(n-1) and 10^n).
/// </para>
/// <para>
/// Wikipedia: https://wikipedia.org/wiki/Prime-counting_function.
/// </para>
/// <para>
/// OEIS: https://oeis.org/A006879.
/// </para>
/// </summary>
public class NumberOfPrimesByNumberOfDigitsSequence : ISequence
{
/// <summary>
/// Gets sequence of number 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;
counter = 0;
powerOf10 *= 10;
}
counter++;
}
}
}
}
C#
1
https://gitee.com/TheAlgorithms/C-Sharp.git
git@gitee.com:TheAlgorithms/C-Sharp.git
TheAlgorithms
C-Sharp
C-Sharp
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891