Binary Exponentiation

Поділитися
Вставка
  • Опубліковано 28 тра 2020
  • Binary exponentiation (or exponentiation by squaring) is an algorithm that quickly computes a big power a^b in O(log(b)). This tutorial for beginners includes the intuition, examples, and two C++ implementations: recursive and iterative. Check out cp-algorithms.com/ for articles on more advanced algorithms.
    Subscribe for more educational videos on algorithms, coding interviews and competitive programming.
    - Github repository: github.com/Errichto/youtube
    - Live streams on 2nd YT channel and on Twitch: / errichto2 & / errichto
    - FB and Twitter: / errichto & / errichto
    - Frequently Asked Questions: github.com/Errichto/youtube/w...

КОМЕНТАРІ • 150

  • @danieldawson8018
    @danieldawson8018 4 роки тому +125

    It's cool to see you get better and better at explaining as time goes on, and you were already good to begin with.
    Thank you, and keep it up!

    • @devendrasingh4776
      @devendrasingh4776 4 роки тому

      Quite obvious as he is a fighter and he knows it.

    • @marvinlessknown3702
      @marvinlessknown3702 Рік тому

      He really is very good. Is he russian?? They're the best teachers / mathematicians I've ever. kantorovich being maybe the greatest??

    • @justsvk1500
      @justsvk1500 Рік тому

      ​@@marvinlessknown3702 polish

  • @shubhamghule4606
    @shubhamghule4606 4 роки тому +93

    Your videos are the reason I started competitive programming 🙌 thanks a lot!

    • @Errichto
      @Errichto  4 роки тому +34

      that's great to hear!

    • @digitalgandu1511
      @digitalgandu1511 3 роки тому +4

      Why ?

    • @fahadhos
      @fahadhos Рік тому

      @@Errichto so your code will support this 5^(10^5)?

    • @hil449
      @hil449 4 місяці тому

      @@fahadhosyes, its lob(b)

  • @rakshithdogra793
    @rakshithdogra793 4 роки тому +39

    Hey Errichto i saw your video and got motivated towards CP and today only i solved my first problem on codeforces thank you bro

    • @Errichto
      @Errichto  4 роки тому +19

      Cool, good luck!

  • @jdhp3696
    @jdhp3696 3 роки тому +10

    Errichto, when you first released it, I didn't understand the concept of it, but decided to save it in my playlist to watch it later. Today, I was solving the daily challenge on Leetcode and suddenly remembered your video. Watching it now, things start clicking for me. Thank you so much. Please make more videos like these.

  • @nickheyer
    @nickheyer 2 роки тому

    I truly appreciate the "over-explanation" of even the more simple concepts. If anything it is a reinforcement that helps drive the concept home, instead of just skimming over it without any actual absorption.

  • @yeetholmes619
    @yeetholmes619 2 роки тому

    I like how you smile when you explain the concept, shows your deep love for the art! A pleasure to learn from you !

  • @tomtan298
    @tomtan298 4 роки тому

    Your videos are the reason I started competitive programming ! Thanks so much for the contribution to this community,keep up the great effort and keep on pumping out more videos for the beginner series :D

  • @TyButNowYouDie
    @TyButNowYouDie 4 місяці тому

    I had already solved this problem recursively before but I didn't understand the iterative solution until watching this video. Your explanation and visualization was really helpful. Thanks!

  • @ANKITVERMA-fl1zn
    @ANKITVERMA-fl1zn 4 роки тому +3

    The Overall Quality of videos are getting better great work indeed! waiting eagerly for Gaussian Elimination.

  • @ritikbaid4318
    @ritikbaid4318 4 роки тому +1

    Great content Erricto!.would be great to see some videos in the future on segment trees as well!

  • @manishsharma2211
    @manishsharma2211 4 роки тому +13

    Errichto , The picasso of CP👌🔥

  • @hardikupadhyay9837
    @hardikupadhyay9837 4 роки тому

    Waiting for some more advanced stuff to come :) This videos are really great

  • @CarlosMartinez-ed7ey
    @CarlosMartinez-ed7ey 9 місяців тому

    Thank you very much, you have a natural talent to explain clearly and make it easy.

  • @SebastianTysler
    @SebastianTysler 3 роки тому

    Thanks Errichto! This is good and easy explanation for fast-power (Binary Exponentiation)

  • @tonystarc9567
    @tonystarc9567 4 роки тому +1

    Errichto you are a savior.... Please keep up doing this good work ... This matters a lot specially in the countries with small per capita income...

  • @ductran7258
    @ductran7258 2 роки тому

    Thank you! Your explanation for this algorithm is awesome!

  • @LearnWithAnmolll
    @LearnWithAnmolll Місяць тому +1

    your article is just awesome

  • @MojahooProducer
    @MojahooProducer 4 роки тому +27

    wow another video, i thought your stream was planning a lot. thanks for your dedication, remember not to push so hard that you burn out!
    youre perhaps even the best educational channel i've seen, the way you explain things helps you understand how to get there too.

  • @ashwinmadke486
    @ashwinmadke486 3 роки тому

    Wonderful explanation ❤️! Understood every little thing. Thankyou 🙏

  • @vinitsharma6630
    @vinitsharma6630 9 місяців тому

    i wasted my time in another video watching it again & again trying to figure this out this made it crystal clear covering every doubt the previous video created like the shift and mod ones

  • @jonathanparlett1172
    @jonathanparlett1172 2 роки тому

    This was super helpful for my cryptography class thank you!

  • @dipankarkumarsingh
    @dipankarkumarsingh 2 роки тому

    thank you for your wonderful explanation... you are an amazing teacher .

  • @shameekagarwal4872
    @shameekagarwal4872 4 роки тому +1

    thats very good!!
    please do cover diophantine equations, fft etc as well...and in such topics maybe include popular question and variations
    thanks!!

  • @johnstephen8041
    @johnstephen8041 3 роки тому

    Thanks much... keep doing these kind of videos.. really helps!

  • @Garentei
    @Garentei 4 роки тому +3

    Best channel ever. This was actually my Facebook interview question.

    • @vikku_19
      @vikku_19 3 роки тому

      Really? Or They asked about of digits? Generally, we're asked about digits of big powers.

    • @Garentei
      @Garentei 3 роки тому

      @@vikku_19 No, it was binary exponentiation. But he didn't explicitly ask me to do so, he asked me to optimize a^b.

  • @vedshrutisarkar4319
    @vedshrutisarkar4319 3 роки тому

    Thank you for a perfect and easy explanation😄

  • @yatharthfrommeerut9006
    @yatharthfrommeerut9006 4 роки тому

    I always thought why we studied this multiplication in principle of programming language. Now I know. Thanks

  • @siddharthpanigrahi3855
    @siddharthpanigrahi3855 3 роки тому

    Thank You, explained really well.

  • @sujan_kumar_mitra
    @sujan_kumar_mitra 2 роки тому

    Best explanation of binary exponentiation

  • @vijendrasaini3050
    @vijendrasaini3050 4 роки тому +13

    Just Watching A.B%N and this one pop out.
    Seems like whole series on NUMBER Theory coming out.😎

    • @Errichto
      @Errichto  4 роки тому +47

      As some people might know from my recent stream, next is matrix exponentiation and gaussian elimination ;) then more advanced topics

    • @loneshaan8531
      @loneshaan8531 4 роки тому

      @@Errichto looking forward

    • @shahbazalam3722
      @shahbazalam3722 4 роки тому

      @@Errichto Excited to learn Matrix Exponentiation.

    • @Gauravverma-ed7fw
      @Gauravverma-ed7fw 4 роки тому

      @Errichto please continue the series for mathematics in CP

    • @Gauravverma-ed7fw
      @Gauravverma-ed7fw 4 роки тому

      @@Errichto please continue series for mathematics in CP

  • @Aman_Panchal27
    @Aman_Panchal27 4 місяці тому

    This video helped a lot. Thanks Man.

  • @hackytech7494
    @hackytech7494 3 роки тому +1

    Thanks for the explanation

  • @rakeshghosh8234
    @rakeshghosh8234 4 роки тому

    Great way.
    Its very nice than previous.

  • @craigmiller9380
    @craigmiller9380 3 роки тому

    Best videos on youtube, thank you!

  • @arushsaxena1213
    @arushsaxena1213 4 роки тому

    great video. It would be awesome if you could make a video on Merge sort tree.

  • @CarrotCakeMake
    @CarrotCakeMake 4 роки тому +2

    It amazing how there exists and algorithm to create an output of size B*log(A) in time log(B).

    • @Errichto
      @Errichto  4 роки тому +1

      The complexity O(log(B)) assumes that multiplication is done in O(1). This makes sense because we mainly compute a huge power modulo P.

  • @kgCode658
    @kgCode658 3 роки тому

    wow u also have great teaching skills ..Thanks for helping

  • @adityatewary7174
    @adityatewary7174 4 роки тому

    Hey, Errichto thanks for the video. Can you also put some questions link in your description box?

  • @souravsaha933
    @souravsaha933 2 роки тому

    Fine answer. Thanks ❤️

  • @em_nikhil_007
    @em_nikhil_007 4 роки тому +3

    Are you kidding me ERRICHTO!!
    How can you read my mind for what topics i need????

  • @omaraljarrah5089
    @omaraljarrah5089 3 роки тому

    When the Matrix expo is coming?
    We have been waiting for a long time now, looking forward to the new video

  • @RamisaAnjum
    @RamisaAnjum 2 роки тому

    12:10
    Thanks, man :D
    I thought I was the only one.

  • @parnabghosh7877
    @parnabghosh7877 3 роки тому

    great explanation !

  • @Ghayth.Moustpha
    @Ghayth.Moustpha 4 роки тому

    Thank you a lot ❤
    Can you please recommend some problems to implemented as a training...
    Thanks again ❤❤💙💙💙

  • @w4rd3nclyffe74
    @w4rd3nclyffe74 4 роки тому

    can you make some videos about fractals in action? also, you're videos are *CRAZYYY* you're so good at explaining stuff

  • @yashrastogi3726
    @yashrastogi3726 4 роки тому

    Thanks man. Keep it up

  • @sajinamin328
    @sajinamin328 4 роки тому

    awesome video bro. take ❤️ from 🇧🇩

  • @Aditya-fx2tv
    @Aditya-fx2tv 4 роки тому

    Love your video errichto ❤

  • @CodeDecipher
    @CodeDecipher 4 роки тому

    Great video you upload 👌 I myself make computer science videos . Can you tell me which mic do you use ?

  • @AbhishekSingh-ws5rz
    @AbhishekSingh-ws5rz 4 роки тому

    Another great video. 😊

  • @asifanwarsajid8332
    @asifanwarsajid8332 3 роки тому

    Kamil, we need more videos from you. :D

  • @SmartCoder89
    @SmartCoder89 4 роки тому

    I like the new background 👍

  • @user-ui2qk6jg5n
    @user-ui2qk6jg5n 4 роки тому

    can u please make a video abot how to setup your cp setup - how to download and use yor ide?
    would also like to see some c++ toturials
    tank you very nuch!

  • @rajshubhankar1725
    @rajshubhankar1725 Рік тому

    Hey what if I remove the 0 condition instead of 1. why just if(b==1) return a is not correct ?

  • @riadhasan9725
    @riadhasan9725 Рік тому

    Very helpful 👍

  • @AbhishekKumar-ky3uc
    @AbhishekKumar-ky3uc 4 роки тому +1

    Hi Errichto, I am a subscriber of your UA-cam channel and admire your work alot.Wanted to ask for an advice , how to learn solution of a problem when it's solution is not present anywhere on internet. Even if I get a hint it's easier. But there are some problems like asked on an interview whose solution afterwards I get nowhere in internet. How to learns solutions of such problems?

  • @097kushagrarawat9
    @097kushagrarawat9 3 роки тому

    really helpful content :)

  • @venkatkumar5220
    @venkatkumar5220 4 роки тому

    Can you do a video on Matrix Exponentiation?

  • @ujjawal_
    @ujjawal_ Рік тому +1

    which whiteboard website you are using

  • @diwyanshukanthwal8669
    @diwyanshukanthwal8669 3 роки тому

    can you tell about left to right binary exponential

  • @preetamvarun9219
    @preetamvarun9219 3 роки тому

    Thank you

  • @ChandraShekhar-by3cd
    @ChandraShekhar-by3cd 4 роки тому +1

    Errichto Your are the "Einstine of CP".

  • @amanrazz2091
    @amanrazz2091 3 роки тому +2

    GOD level explantation .... 🖤

  • @omaraljarrah5089
    @omaraljarrah5089 4 роки тому

    Thank U, U are awesome 🤘🌨❄

  • @rohanprak
    @rohanprak 4 роки тому +1

    @errichto *please* make a video on Segment tree
    *iterative* with *lazy propagation* , everyone teaches recursive one, with memory 4*n and 5 arguments !!
    non recursive if okay till point updates, but range updates ( lazy propagation ) seems way too complicated.
    please make a video on *lazy update* on *non recursive segment* tree, we belief you will make it simpler, and also no video on you-tube exists on it.

  • @shubhamghule4606
    @shubhamghule4606 4 роки тому +14

    Missing the teddy 🧸!

    • @climbnexplore1187
      @climbnexplore1187 4 роки тому +1

      But instead we have alcohol left of errichtos shoulder... wait why does Oxygen have three connections ?

    • @shubhamghule4606
      @shubhamghule4606 4 роки тому

      @@climbnexplore1187 Its carbon bro !

  • @HelloWorld-sy4yc
    @HelloWorld-sy4yc 4 роки тому

    Do u have a blog or channel in telegram for instance?

  • @dadisuperman3472
    @dadisuperman3472 Рік тому

    Did you added the tag "Easy" on the thumbnail of the video?
    It was not there before.

  • @baxi9227
    @baxi9227 4 роки тому +4

    don't forget to flex how you came up with matrix expo yourself

    • @Errichto
      @Errichto  4 роки тому +5

      Is it that important though? :D

    • @mksybr
      @mksybr 4 роки тому +1

      @@Errichto What video was that?

  • @enside8822
    @enside8822 3 роки тому

    Thank you!!!

  • @VachaspatiMishra99
    @VachaspatiMishra99 4 роки тому +4

    Dimitri finds out.

  • @ahsanulameensabit
    @ahsanulameensabit 4 роки тому

    Waiting for the next one...

  • @kakashisenpai99
    @kakashisenpai99 4 роки тому +1

    Bro post your Hackerrank problem , 'Lisa's Workbook' approach and solution!

  • @falseee4445
    @falseee4445 4 роки тому

    Thanks !

  • @i.anandsingh
    @i.anandsingh 4 роки тому

    can you please explain how to find PRIMITIVE ROOTS,? and EULER'S TOTIENT FUNCTION.

  • @tarsala1995
    @tarsala1995 4 роки тому +1

    You can calculate 9^9
    I remember that it's 387420489
    But it doesn't really matter

  • @amalsakkoumi1392
    @amalsakkoumi1392 3 роки тому

    If a^-b how we can slove it please

  • @harshamusunuri1924
    @harshamusunuri1924 Рік тому

    I don't understand the iterative part, is there any other simpler way to understand this?

  • @hil449
    @hil449 4 місяці тому

    didnt understand a single thing from the inverse part but ok, great video

  • @iliavasilenko4961
    @iliavasilenko4961 4 роки тому

    Is it normal when somebody uses ints instead of long long?

  • @aquibansari3941
    @aquibansari3941 3 роки тому

    can anyone please tell which tool is he using to draw and sketch

    • @sakshamjain6900
      @sakshamjain6900 3 роки тому

      software is ONE NOTE available on windows 10 and he is using graphic tablet to draw on screen (a board and a pen)!

  • @himanshudixit490
    @himanshudixit490 3 роки тому

    Problem: You are given a sequence of length n. Apply to it a given permutation k times.
    Solution: Simply raise the permutation to k-th power using binary exponentiation, and then apply it to the sequence. This will give you a time complexity of O(nlogk)
    Can anybody explain what its talking about ?

  • @abhudyasingh9109
    @abhudyasingh9109 4 роки тому

    How to calculate pow(a,pow(b,c)) under modulo

  • @MrPatrickbuit
    @MrPatrickbuit 4 місяці тому

    I understand it completely but it’s another one of those things I would not have come up with

  • @i_am_wiz
    @i_am_wiz 3 роки тому

    I didn’t understand how 0th bit contributes to a....1st bit to a^2.....2nd bit to a^4.....and so on.....can anyone please help?

  • @ankitchoudhury9678
    @ankitchoudhury9678 Рік тому

    Damnnn.. love you

  • @PankajKumarGladiator
    @PankajKumarGladiator 4 роки тому +7

    10:54 😂That awkward moment 😂 !!

  • @shoryasinghal5241
    @shoryasinghal5241 Рік тому

    good eric

  • @rujixie9025
    @rujixie9025 3 роки тому

    So neat

  • @sawvikdipto3087
    @sawvikdipto3087 7 місяців тому

    Only for My help. Please ignore.
    def p(a,b):
    res=1
    while b>0:
    if b%2==1:
    res=res*a
    a=a*a
    b=b//2
    return res

  • @node3079
    @node3079 3 роки тому

    4:57 Can someone please explain ..thanks🙏

  • @5590priyank
    @5590priyank 4 роки тому

    geeky background :)

  • @anmol_tomer
    @anmol_tomer 4 роки тому +1

    I am a simple man, if(Errichto uploads) { make notes && like the video} # :D

  • @debadityasutradhar7962
    @debadityasutradhar7962 3 роки тому

    why cant we just use pow(a,b) by taking a & b as input

  • @mdfahad2726
    @mdfahad2726 4 роки тому +5

    I love your background 😍.
    Any specific reason why it contains High school physics, chemistry, maths equations?

    • @Errichto
      @Errichto  4 роки тому +2

      All science is beautiful, isn't it?

  • @tombrady7390
    @tombrady7390 3 роки тому

    wow 200k kamil take a bow

  • @hamzakhiar3636
    @hamzakhiar3636 3 роки тому

    you said recurssive programs are slower than iterative programs why

  • @yashagarwal3999
    @yashagarwal3999 3 роки тому

    it is not at all working in python please help simebody

  • @joyo2122
    @joyo2122 3 роки тому

    🙏

  • @aryanyadav3926
    @aryanyadav3926 Рік тому +1

    Didn't understand the inverse part.
    Rest was good