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

                }
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值