Скоро Codeforces Round 1133 (Div. 1, Div. 2)! Регистрация здесь. ×

Блог пользователя srijon_32

Автор srijon_32, история, 2 года назад, По-английски

I was looking for a solution to a problem. I saw this in a function of that solution:

bool good(ll mid) { ll x = sqrt ( mid ); while( x * x > mid ) x-- ; while( ( x + 1 ) * ( x + 1 ) <= mid ) x++ ; return mid -x >= k; }

how is it possible that: sqrt ( mid ) * sqrt ( mid ) > mid ? or ( sqrt ( mid ) + 1 ) * ( sqrt ( mid ) + 1 ) <= mid ?

all this sqrt has floor value.

That problem link: https://codeforces.me/contest/2020/problem/B

  • Проголосовать: нравится
  • +17
  • Проголосовать: не нравится

»
2 года назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

sqrt acts on floating point, so there can be slight imprecision issues that require you to shift it around to get it to be correct. But it's much faster to use this to find the integer square root than to binary search.

»
2 года назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

Use sqrtl()

or try submitting in C++17