对分查找
int BinarySearch(const int A[], int x, int N) { int low, mid, high; low = 0, high = N - 1; while(low <= high) { mid = (low + high) / 2; if(A[mid] < x) low = mid + 1; else if(A[mid] > x) high = mid - 1; else return mid; } return NotFound; }
欧几里得算法求最大公因数:
unsigned Gcd(unsigned int M, unsigned int N) { unsigned int Rem; while(N > 0) { Rem = M % N; M = N; N = Rem; } return M; }