primality test
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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; }
square root (Newton's method)
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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; }
Harmonic number
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public static double H(int N){ double sum = 0.0; for(int i=1; i < N; i++) sum += 1.0/i; return sum; }
Binary Research
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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; }