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

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

Given 4 numbers A,B,C and D. If A ^ B > C ^ D print "YES" otherwise, print "NO".

Input : Only one line containing 4 numbers A,B,C and D (1 ≤ A,C ≤ 10^7 ) , (1 ≤ B,D ≤ 10^12 )

Output : Print "YES" or "NO" according to the problem above.

Problem Link — Here

I think I have to mod this. But what's the real approach?

TIA.

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

»
4 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Take log on both sides. Check for b*log(a) > d*log(c).Submission link : 92842700

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Didn't get you, can you please explain, if you don't mind

    • »
      »
      »
      4 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Generally, Log(a^b) is b*Log(a). The log of a larger number will be greater than the log of a smaller number. Taking Logarithm allows comparing larger numbers.

    • »
      »
      »
      2 месяца назад, # ^ |
      Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

      Translation of the expression A^B to log(A^B) is just scaling the expression while maintaining the proportion. So the comparison less than or greater than still works.

      Remember that the logarithm is like asking for a number that need to be the power of other number to be equal to something: log(a^b) = y

      SUM PROPERTY
      You need to first need to understand: log(A*B) = log(A) + log(B)

      Let's say:
      --> X = logb(M)
      --> Y = logb(N)

      Then:
      b^X = M
      b^Y = N

      Then:
      M*N = b^X * b^Y = b^(X+Y)

      Logarithm in both sides:
      logb(M*N) = logb(b^(X+Y)) // Here both bases cancel each other. Example: log10(10) == 1
      So we ended up with: logb(M*N) = X + Y

      Then just rewrite X and Y: logb(M*N) = logb(M) + logb(N)

      The next steps are easy:

      log(A*A) = log(A) + log(A) = log(A^2)

      A^3 = A*A*A
      log(A*A*A) = log(A) + log(A) + log(A) = log(A^3) = 3 * log(A)

      So log(A^B) = B * log(A)