Just a reminder

Revision en5, by Abito, 2023-03-24 09:42:56

Don't use sqrt because precision issues

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

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en5 English Abito 2023-03-24 09:42:56 2054
en4 English Abito 2023-03-24 09:36:13 0 (published)
en3 English Abito 2023-03-24 09:36:03 87 (saved to drafts)
en2 English Abito 2023-03-23 20:18:13 306 Tiny change: 'n issues\nimplemen' -> 'n issues\n\nimplemen'
en1 English Abito 2023-03-23 20:15:43 2107 Initial revision (published)