public int sqrt(int x) {
        if(x < 1) return 0;
        if(x < 4) return 1;
        int ans = x / 2, pre;
        do{
            pre = ans;
            ans = (ans + x / ans) / 2;
            if(pre < ans) return pre;
        } while(ans != pre);
        
        return ans;
    }