Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

LovesProgramming's blog

By LovesProgramming, history, 5 years ago, In English

I want to calculate ((a/b)^n)%e.

I know, how to calculate (a/b)%e; the formula is: (a%e * (b^-1%e))%e.

So, the answer to the above question should be,

(a^n%e * ((b^n)^-1)%e)%e

Am I right ?

Plus, I know how to calculate b^-1 , but I want to know, how to calculate (b^n)^-1

Thanks .

  • Vote: I like it
  • -11
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Is e a prime number? Let x = (a/b)%e then ((a/b)^n)%e = (x^n)%e.

UPD: ((b^n)^-1)%e = ((b^-1)^n)%e

  • »
    »
    5 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I've found a nice way :-) Thanks, anyways!!

    • »
      »
      »
      5 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      (b^n)^-1 you can do fast exponentiation with modulo then invert it as it is written.