Binary Exponentiation
ฝัง
- เผยแพร่เมื่อ 4 ต.ค. 2024
- 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.... for articles on more advanced algorithms.
Subscribe for more educational videos on algorithms, coding interviews and competitive programming.
Github repository: github.com/Err...
Live streams on 2nd YT channel and on Twitch: / errichto2 & / errichto
FB and Twitter: / errichto & / errichto
Frequently Asked Questions: github.com/Err...
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!
Quite obvious as he is a fighter and he knows it.
He really is very good. Is he russian?? They're the best teachers / mathematicians I've ever. kantorovich being maybe the greatest??
@@marvinlessknown3702 polish
Your videos are the reason I started competitive programming 🙌 thanks a lot!
that's great to hear!
Why ?
@@Errichto so your code will support this 5^(10^5)?
@@fahadhosyes, its lob(b)
Hey Errichto i saw your video and got motivated towards CP and today only i solved my first problem on codeforces thank you bro
Cool, good luck!
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.
Hi Errichto, I hope you are doing great, just wanted to let you know that you are the reason I got into competitive programming and now I am addicted to it. Cheers
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.
Errichto , The picasso of CP👌🔥
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.
:3
I like how you smile when you explain the concept, shows your deep love for the art! A pleasure to learn from you !
Best channel ever. This was actually my Facebook interview question.
Really? Or They asked about of digits? Generally, we're asked about digits of big powers.
@@vikku_19 No, it was binary exponentiation. But he didn't explicitly ask me to do so, he asked me to optimize a^b.
The Overall Quality of videos are getting better great work indeed! waiting eagerly for Gaussian Elimination.
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...
your article is just awesome
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
Thank you very much, you have a natural talent to explain clearly and make it easy.
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
Just Watching A.B%N and this one pop out.
Seems like whole series on NUMBER Theory coming out.😎
As some people might know from my recent stream, next is matrix exponentiation and gaussian elimination ;) then more advanced topics
@@Errichto looking forward
@@Errichto Excited to learn Matrix Exponentiation.
@Errichto please continue the series for mathematics in CP
@@Errichto please continue series for mathematics in CP
Thanks Errichto! This is good and easy explanation for fast-power (Binary Exponentiation)
It amazing how there exists and algorithm to create an output of size B*log(A) in time log(B).
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.
Best explanation of binary exponentiation
Great content Erricto!.would be great to see some videos in the future on segment trees as well!
I always thought why we studied this multiplication in principle of programming language. Now I know. Thanks
Are you kidding me ERRICHTO!!
How can you read my mind for what topics i need????
Really good explanation. Ty!
Thanks for the explanation
Thank you! Your explanation for this algorithm is awesome!
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!
12:10
Thanks, man :D
I thought I was the only one.
Waiting for some more advanced stuff to come :) This videos are really great
This was super helpful for my cryptography class thank you!
Missing the teddy 🧸!
But instead we have alcohol left of errichtos shoulder... wait why does Oxygen have three connections ?
@@climbnexplore1187 Its carbon bro !
GOD level explantation .... 🖤
This video helped a lot. Thanks Man.
thank you for your wonderful explanation... you are an amazing teacher .
thats very good!!
please do cover diophantine equations, fft etc as well...and in such topics maybe include popular question and variations
thanks!!
Wonderful explanation ❤️! Understood every little thing. Thankyou 🙏
Thanks much... keep doing these kind of videos.. really helps!
Fine answer. Thanks ❤️
Errichto Your are the "Einstine of CP".
@@audiogear4412 Yes I do.
Best videos on youtube, thank you!
Thank you for a perfect and easy explanation😄
Great way.
Its very nice than previous.
Hi Errichto, I am a subscriber of your TH-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?
Thank You, explained really well.
wow u also have great teaching skills ..Thanks for helping
10:54 😂That awkward moment 😂 !!
Thanks a lot man!
I like the new background 👍
Very helpful 👍
@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.
Kamil, we need more videos from you. :D
great video. It would be awesome if you could make a video on Merge sort tree.
didnt understand a single thing from the inverse part but ok, great video
You can calculate 9^9
I remember that it's 387420489
But it doesn't really matter
great explanation !
I love your background 😍.
Any specific reason why it contains High school physics, chemistry, maths equations?
All science is beautiful, isn't it?
I am a simple man, if(Errichto uploads) { make notes && like the video} # :D
awesome video bro. take ❤️ from 🇧🇩
Hey, Errichto thanks for the video. Can you also put some questions link in your description box?
Thanks man. Keep it up
can you make some videos about fractals in action? also, you're videos are *CRAZYYY* you're so good at explaining stuff
don't forget to flex how you came up with matrix expo yourself
Is it that important though? :D
@@Errichto What video was that?
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!
Great video you upload 👌 I myself make computer science videos . Can you tell me which mic do you use ?
When the Matrix expo is coming?
We have been waiting for a long time now, looking forward to the new video
Thank you
which whiteboard website you are using
Bro post your Hackerrank problem , 'Lisa's Workbook' approach and solution!
respecckt
Another great video. 😊
Love your video errichto ❤
Did you added the tag "Easy" on the thumbnail of the video?
It was not there before.
really helpful content :)
Thank you a lot ❤
Can you please recommend some problems to implemented as a training...
Thanks again ❤❤💙💙💙
I understand it completely but it’s another one of those things I would not have come up with
Thank U, U are awesome 🤘🌨❄
Can you do a video on Matrix Exponentiation?
Thank you!!!
good eric
Waiting for the next one...
Dimitri finds out.
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 ?
Thanks !
Damnnn.. love you
can you tell about left to right binary exponential
I don't understand the iterative part, is there any other simpler way to understand this?
why cant we just use pow(a,b) by taking a & b as input
Hey what if I remove the 0 condition instead of 1. why just if(b==1) return a is not correct ?
wow 200k kamil take a bow
can you please explain how to find PRIMITIVE ROOTS,? and EULER'S TOTIENT FUNCTION.
So neat
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?
How to calculate pow(a,pow(b,c)) under modulo
Is it normal when somebody uses ints instead of long long?
If a^-b how we can slove it please
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
geeky background :)
Do u have a blog or channel in telegram for instance?
🙏
you said recurssive programs are slower than iterative programs why
Because recursion uses stack data structure to hold these functions and it takes mounting and unmounting time to switch between functions. But iterative keeps running in one go. Slightly faster. Use javas currunt time millis and run a big test case you might see some milliseconds difference
Didn't understand the inverse part.
Rest was good