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

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

I have a number A and a number B(which is very large calculated by NcR or C(N,R) modulo 10e9+7) and i want to find A^B(A raise to the power B) but by fast exponentation i get wrong answer. Like for example A=2 and B=6 and mod=5 then actual answer is(2^6)%5=4 but since i have to use mod at every step my answer is (2^(6%5))%5=2. I can't store B in a number because it's too large.How should i go about it?Thanks in advance.

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

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

This is a problem from an ongoing contest.

  • »
    »
    8 лет назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится -52 Проголосовать: не нравится

    Did i ask a solution to the problem or just a small part (that too computational) of it? Moreover these contest are to learn a new thing and so i wanted to learn this thing.You also know this is just the last part of the problem and to reach here you've to use your brain and from here it's just some technique which someone knows and some don't.Therefore i want to know the technique.If you don't want to help then it's Okay.Maybe you find it asking the solution.I searched google for the answer but couldn't get it therefore i asked it here.You mean i should sit idle without looking to learn this technique.I know i'll learn faster if i get to know this now.Please brother don't think otherwise for me.

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -13 Проголосовать: не нравится

How big can B be?

»
8 лет назад, скрыть # |
 
Проголосовать: нравится -22 Проголосовать: не нравится

It can be computed using ((A%mod)^(B%(mod-1)))%mod