【Project Euler】3 第三题


//The prime factors of 13195 are 5, 7, 13 and 29.
        //What is the largest prime factor of the number 600851475143 ?
        static void Main(string[] args)
        {
            //int[] number = new int[100];
            long[] number = new long[1228];                  //通过count计数得到容器一共收录1228个long型数据
            ArrayList list = new ArrayList();
            //int count = 0;
            for (int i = 3; i < 10000; i++)
            {
                int index = -1;
                for (int j = 2; j < i; j++)
                {
                    if (i % j != 0 && i != j)
                    {

                    }
                    else
                    {
                        index += 1;
                    }
                }
                if (index == -1)
                {
                    list.Add(i);
                    //Console.WriteLine(i);
                    //count += 1;
                }
            }
            long num = 0;
            for (int i = 0; i < 1228; i++)
            {
                string str = list[i].ToString();
                num = long.Parse(str);
                //Console.WriteLine(num);
                number[i] = num;
            }
            //Console.WriteLine(count);                  //以上均为计算10000以内的所有的所有质数代码

            //int max = 13195;
            long max = 600851475143;
            for (int i = 0; i < 1228; i++)
            {
                if (max % number[i] == 0)
                {
                    Console.WriteLine(number[i]);
                    max = max / number[i];               //如果该值除以某质数余数为0,则进行除法运算更换该值

                }
            }
        }

时间: 2024-07-30 18:42:51

【Project Euler】3 第三题的相关文章

【Project Euler】1 第一题

 //If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. //Find the sum of all the multiples of 3 or 5 below 1000.  static void Main()         {             int sum=0;     

【Project Euler】2 第二题

 //Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: //1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... //By considering the terms in the Fibonacci sequence whose valu

【Project Euler】9 第九题

 A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. static void Main(s

使用CoffeeScript来解决Project Euler中的编程问题

本 系列 文章将探讨 CoffeeScript,这是构建于 http://www.aliyun.com/zixun/aggregation/33906.html">JavaScript 基础之上的一种全新编程语言,它提供了非常干净的语法.CoffeeScript 可编译为高效的 JavaScript.除了在 Web 浏览器中运行 JavaScript 之外,您还可以将它与服务器应用程序的 Node.js 等技术一起使用.在 第 1 部分 中,学习了如何设置 CoffeeScript 编译器

用python解决project euler中的题目

寒假期间学习了python,现在基本上就能上手使用它来解决project euler里面的题目了,用python真的是没得说的,一个字"赞".在C++中需要用一大堆代码实现的算法,在python中,只需要那么短短几行.而且还有惊艳的运行速度.借用<可爱的python>里面的一句话:"人生苦短,我用python". [project euler 055] 求经过一系列规则不能得到回文数的数的个数.题目在此: If we take 47, reverse a

经典算法题每日演练——第三题 猴子吃桃

原文:经典算法题每日演练--第三题 猴子吃桃           猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾就多吃了一个.第二天早上又将剩下的桃子吃了一半,还是不过瘾又多 吃了一个.以后每天都吃前一天剩下的一半再加一个.到第10天刚好剩一个.问猴子第一天摘了多少个桃子?   分析: 这是一套非常经典的算法题,这个题目体现了算法思想中的递推思想,递归有两种形式,顺推和逆推,针对递推,只要         我们找到递推公式,问题就迎刃而解了.                令S10=1,容易看

leetcode-Leetcode第三题,本地运行72ms,为何提交后TLE?

问题描述 Leetcode第三题,本地运行72ms,为何提交后TLE? 题目链接:https://leetcode.com/problems/longest-substring-without-repeating-characters/ 使用了HashSet,会不会是因为Mono的HashSet实现比微软的性能差很多?本地跑相同测试用例只用了72ms,提交后还是TLE 代码如下: public int LengthOfLongestSubstring(string s) { if (s.Leng

阿里聚安全攻防挑战赛第三题Android PwnMe解题思路

阿里聚安全攻防挑战赛第三题Android PwnMe解题思路 大家在聚安全挑战赛正式赛第三题中,遇到android app 远程控制的题目.我们今天带你一探究竟,如何攻破这道题目. 一.题目 购物应用pwn (6分) 环境: - 要求在ARM 64位Android手机上攻击成功,也可在模拟器(运行Google官方Android SDK提供的Google APIs ARM64 Android 7.0镜像)中攻击成功,其中镜像会打包提供,参见题目下载链接.模拟器执行命令参考如下:(qemu-syst

Project euler 18题解答

 By starting at the top of the triangle below and moving to adjacent numbers on the row below, the maximum total from top to bottom is 23. 37 4 2 4 6 8 5 9 3 That is, 3 + 7 + 4 + 9 = 23. Find the maximum total from top to bottom of the triangle below