• 【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,则进行除法运算更换该值

                    }
                }
            }

    版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    Running MYSQL 5.7 By Bash On Ubuntu On Windows:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    MiniDao FreeMarker Cache 缓存问题
    Minidao FreeMarker 数组
    插入排序实例
    Binutils工具集中的一些比较常用的工具
    交叉编译工具简介
    TQ2440触摸屏
    对IIC总线时序的一点理解以及ACK和NACK(NAK)
    UART,SPI,IIC的一点理解
    linux中vi显示中文乱码的问题
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786199.html
Copyright © 2020-2023  润新知