相关疑难解决方法(0)

如何有效地计算连续数字的数字产品?

我正在尝试计算一系列数字的每个数字的数字乘积,例如:

21,22,23 ...... 98,99 ..

将会:

2,4,6 ... 72,81 ..

为了减少复杂性,我会考虑只有[ 连续编号中的数字的有限长度],如从001999或从00019999.

但是,例如,当序列很大时1000000000,重复提取数字然后乘以每个数字将是低效的.

基本思路是跳过我们在计算过程中会遇到的连续零点,如:

using System.Collections.Generic;
using System.Linq;
using System;

// note the digit product is not given with the iteration
// we would need to provide a delegate for the calculation
public static partial class NumericExtensions {
    public static void NumberIteration(
            this int value, Action<int, int[]> delg, int radix=10) {
        var digits=DigitIterator(value, radix).ToArray();
        var last=digits.Length-1;
        var …
Run Code Online (Sandbox Code Playgroud)

c# language-agnostic math

7
推荐指数
1
解决办法
2676
查看次数

标签 统计

c# ×1

language-agnostic ×1

math ×1