public int sqrt(int x) {
		if(x <= 0) return 0;
		if(x == 1) return 1;
		
		int res = x / 2, pre = -1;
		while(res != pre) {
			pre = res;
			res = (res + x / res) / 2;
			if(res > pre) return pre; // bug here, forgot to add this
		}
		return res;
	}