zoukankan      html  css  js  c++  java
  • 蓝桥杯 矩阵翻硬币

    思路:

    参考了http://blog.csdn.net/snailset/article/details/26752435,思路很清晰。

    用java实现了高效的牛顿迭代法。

    我tm都要爱上java了。

    实现:

     1 import java.math.*;
     2 import java.util.*;
     3 
     4 public class Main {
     5 
     6     public static BigInteger sqrt(BigInteger x){
     7         if (x .equals(BigInteger.ZERO) || x.equals(BigInteger.ONE)) {
     8             return x;
     9         }
    10         BigInteger two = BigInteger.valueOf(2L);
    11         BigInteger y;
    12         for (y = x.divide(two);
    13              y.compareTo(x.divide(y)) > 0;
    14              y = ((x.divide(y)).add(y)).divide(two));
    15         return y;
    16     }
    17 
    18     /**
    19      * @param args
    20      */
    21     public static void main(String[] args) {
    22         // TODO Auto-generated method stub
    23         BigInteger n;
    24         Scanner s = new Scanner(System.in);
    25         BigInteger a = s.nextBigInteger();
    26         BigInteger b = s.nextBigInteger();
    27         BigInteger ia = sqrt(a);
    28         BigInteger ib = sqrt(b);
    29         System.out.println(ia.multiply(ib));
    30     }
    31 }
  • 相关阅读:
    随便发泄几句
    四年有感
    测试产品杂谈
    质量管理杂谈
    提升
    下半年工作方向
    测试资源分配
    2013思路
    微博吐槽汇总
    招聘
  • 原文地址:https://www.cnblogs.com/wangyiming/p/6659525.html
Copyright © 2011-2022 走看看