zoukankan      html  css  js  c++  java
  • 【唉

    primality test

    public static boolean isPrime(int N) {
        if(N < 2) return false;
        for(int i = 2; i * i < N; i++)
            if(N % i == 0) return false;
        return true;
    }
    View Code

    square root (Newton's method)

    public static double sqrt(double c){
        if (c < 0) return Double.NaN;
        double err = le-15;
        double t = c;
        while (Math.abs(t - c/t) > err * t)
            t = (t + c/t) / 2.0;
        return t;
    }
    View Code

    Harmonic number

    public static double H(int N){
        double sum = 0.0;
        for(int i=1; i < N; i++)
            sum += 1.0/i;
        return sum;
    }
    View Code

    Binary Research

    public static int rank (int key; int[] a) {
        return rank(key, a, 0, a.length - 1);
    }
    public static int rank (int key; int[] a; int lo; int hi) {
        if (lo > hi) return -1;
        int mid = lo + (lo + hi)/2;
        if (key < a[mid]) return rank(key, a, lo, mid - 1);
        else if (key > a[mid]) return rank(key, a, mid + 1, hi);
        else                          return mid;
    }
    View Code
  • 相关阅读:
    terminal
    变量提升、函数提升
    ssh传输文件
    mocha测试框架
    npm-run 自动化
    webpack
    浅析babel
    构建工具gulp
    C++中TRACE宏及assert()函数的使用
    memcpy函数-C语言
  • 原文地址:https://www.cnblogs.com/moonlightshadow/p/7278518.html
Copyright © 2011-2022 走看看