Just a reminder

Правка en4, от Abito, 2023-03-24 09:36:13

Don't use sqrt because precision issues

implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search implement sqrt using binary search

Also here is implementation to find floor(sqrt(x))

#define int long long
int sqrt(int x){
    int l=1,r=1e9+5,ans=0,mid;
    while (l<=r){
        mid=(l+r)/2;
        if (mid*mid<=x){
            ans=mid;
            l=mid+1;
        }else r=mid-1;
    }return ans;
}

It seems std::sqrt works fine in C++17 though. Also sqrtl seems to give correct results

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en5 Английский Abito 2023-03-24 09:42:56 2054
en4 Английский Abito 2023-03-24 09:36:13 0 (published)
en3 Английский Abito 2023-03-24 09:36:03 87 (saved to drafts)
en2 Английский Abito 2023-03-23 20:18:13 306 Tiny change: 'n issues\nimplemen' -> 'n issues\n\nimplemen'
en1 Английский Abito 2023-03-23 20:15:43 2107 Initial revision (published)