Greplin 编程挑战 Lv.2

发布于 2024-10-18 06:45:13 字数 966 浏览 7 评论 0原文

挑战位于此处

好的,我找到了要拨打的号码,我只是不明白如何处理结果(这可能与我有限的数学经验有关)

所以我计算了第一个比电话给出的素数斐波那契数更大的数,

所以让我们将该数字称为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;  
        }

Challenge located here

Okay so I figured out the number to call in I just don't understand what to do with the result (this could probably have something to do with my limited experince in mathamatics)

so I calc the first Prime fibonacci number larger than the one given over the phone

so lets call that number x

but now I don't under stand the "sum of the prime devisors +1"

as I understand it X is prime so there for the prime devisors are 1 and X

unless its (x+1) to then find the devisors (array D) then find the numbers in D that are prime (array Pd)

Pd1+Pd2= answer

Am I barking up the right tree?

My source code thus far ( I Can provide the is prime code if needed i assume its not)

 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;  
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青柠芒果 2024-10-25 06:45:13

我错过了答案是数字 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;
        }

I miss read the answer is the sum of all prime factors of the number x

Here is the updated code: (please feel free to comment on the code)

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;
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文