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

  • 相关阅读:
    Eclipse安装aptana
    mysql获取下一篇和上一篇文章的ID
    Java回顾之Spring基础
    纯CSS实现各类气球泡泡对话框效果
    百度编辑器ueditor的简单使用
    实施接口
    Java快速教程
    Java GUI程序设计
    JAVA之关于This的用法
    Java 数组基础
  • 原文地址:https://www.cnblogs.com/facingwaller/p/2388191.html
Copyright © 2011-2022 走看看