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

Автор Kaneki_04, история, 9 лет назад, По-английски

I was thinking of a way to solve this problem in O(1) and I am not getting the right answer..

My logic was that..

the answer is (a+b)(a+1)(b+1)/2 and the equation is x+my=mc(I changed b to c for convinience..)

so upon applying the am>=gm inequality in the following way..

((a+b)+(a+1)+(2*m-1)(b+1)/3>=((2*m-1)^1/3)*answer

so answer would be floor(LHS/(2*m-1)^1/3) and LHS is (2*m*c+2*m)/3 as (a,b) lies on the line..

but I was getting a wrong answer..

Sorry if I missed something obvious and any help would be really appreciated..

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

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

Hi, well first of all the right side of your inequality should be ((2*m -1)*2*ans)^1/3 instead of ((2*m-1)^1/3)*ans, but then when you found x = floor(...) you found the biggest integer solution that satisfies your inequality, however it may be impossible for (a+b)(a+1)(b+1)/2 to take the value of x, so you must find the largest integer solution for (a+b)(a+1)(b+1)/2 = y where y <= x which can be tricky but with some help from wolfram alpha is possible. BTW i really like the way you used am>=gm to solve this problem in O(1).