zoukankan      html  css  js  c++  java
  • 【欧拉3】最大质因数

    问题描述:

    The prime factors of 13195 are 5, 7, 13 and 29.

    What is the largest prime factor of the number 600851475143 ?

    public class Q3 {

          /// <summary>
          /// 取得最大的质因数
          /// </summary>
          /// <param name="max">The max.</param>
          /// <returns></returns>
          public static long q3(long max) {
              //遍历可能的质因数2 到。。
              List<long> math = new List<long>();
              for (long i = 2;max != 1; i++) {

                  while (max % i == 0) {
                      math.Add(i);
                      max = max / i;
                  }

              }
              return math.Distinct().Max();
          }

          public static void test() {
              var t1 = DateTime.Now;
              Console.WriteLine(" " + q3(600851475143) + " cast time " + (DateTime.Now - t1).TotalSeconds);

          }
      }

    image

  • 相关阅读:
    数据结构-二叉搜索树
    多任务处理方式之一:多进程
    TCP并发服务器
    REST是什么?RESTFul又是什么?这二者的关系是怎样的?
    Python中的深浅拷贝的区别
    查找算法之 '二分法查找'
    排序算法之 '快速排序'
    CCS
    CCS
    CCS
  • 原文地址:https://www.cnblogs.com/facingwaller/p/2388191.html
Copyright © 2011-2022 走看看