zoukankan      html  css  js  c++  java
  • 高精度最小公倍数

    最小公倍数

    为什么1小时有60分钟,而不是100分钟呢?这是历史上的习惯导致。
    但也并非纯粹的偶然:60是个优秀的数字,它的因子比较多。
    事实上,它是1至6的每个数字的倍数。即1,2,3,4,5,6都是可以除尽60。

    我们希望寻找到能除尽1至n的的每个数字的最小整数m.

    输入

     多组测试数据(少于500组)。
    每行只有一个数n(1<=n<=100).

    输出

    输出相应的m。

    样例输入

    2
    3
    4
    

    样例输出

    2
    6
    12
    
    import java.math.BigInteger;
    import java.text.DecimalFormat;
    import java.util.*;
    public class Main {
         
        public static void main(String[] args) {
       
      Scanner cin = new Scanner (System.in);
      BigInteger a, b, c = BigInteger.ONE;
      int n;
      while(cin.hasNext()){
          n = cin.nextInt();
          c = BigInteger.ONE;
          for(int i  = 2; i <= n; i++){
              b = BigInteger.valueOf(i);
              a = b.gcd(c);
              c = c.multiply(b);
              c = c.divide(a);
          }
          System.out.println(c);
      }
     }
    }
    View Code
  • 相关阅读:
    解释之前遗留的方法覆盖问题
    多态在开发中的作用
    多态的基础语法
    Go 统计汉子字符
    Go map
    Go make和new的区别
    Go 指针
    Go 切片
    Go数组
    Go中交换两个值类型
  • 原文地址:https://www.cnblogs.com/cshg/p/5654363.html
Copyright © 2011-2022 走看看