Greplin编程挑战Lv.2

时间:2011-02-16 20:59:18

标签: c# math primes factorization

挑战位于here

好吧所以我想出要拨打的号码我只是不明白该怎么处理结果(这可能与我在mathamatics中的有限经验有关)

所以我计算了第一个Prime斐波那契数字大于通过电话给出的数字

所以我们打电话给那个号码x

但现在我并不认为“主要设计者总和+1”

据我所知,X是素数,所以主要的设计师是1和X

除非它(x + 1)然后找到设计者(数组D)然后找到D中的数字是素数(数组Pd)

Pd1 + Pd2 =回答

我咆哮着正确的树吗?

到目前为止我的源代码(如果需要,我可以提供主要代码,我假设它不是)

 private static long CalcPassword2(long p)
        {
            p++;
            List<int> factors = new List<int>();

            for (int i = 1; i <= p; i++)
            {
                if (p % i == 0)
                    if (isprime(i))
                    {
                        factors.Add(i);
                    }
            }
            if (factors.Count >= 2)
            {
                factors.Sort();
                factors.Reverse();
                return factors[0]+factors[1];
            }

                return 1;  
        }

1 个答案:

答案 0 :(得分:1)

我想念的答案是数字x

的所有素因子的总和

以下是更新后的代码:(请随时评论代码)

private static long CalcPassword2(long p)
        {
            p++;
            List<int> factors = new List<int>();

            for (int i = 1; i <= p; i++)
            {
                if (p % i == 0)
                    if (isprime(i))
                    {
                        factors.Add(i);
                    }
            }
            int answer = 0;
            foreach (int prime in factors)
            {
                answer = answer + prime;
            }
            return answer;
        }