|
7977 | 7977 |
|
7978 | 7978 |
|
7979 | 7979 |
|
| 7980 | + |
| 7981 | + |
| 7982 | + |
| 7983 | + |
| 7984 | + |
| 7985 | + |
| 7986 | + |
| 7987 | + |
| 7988 | + |
| 7989 | + |
| 7990 | + |
| 7991 | + |
7980 | 7992 |
|
7981 | 7993 |
|
7982 | 7994 |
|
|
7985 | 7997 |
|
7986 | 7998 |
|
7987 | 7999 |
|
| 8000 | + |
| 8001 | + |
| 8002 | + |
| 8003 | + |
7988 | 8004 |
|
7989 | 8005 |
|
7990 | 8006 |
|
|
8267 | 8283 |
|
8268 | 8284 |
|
8269 | 8285 |
|
| 8286 | + |
| 8287 | + |
| 8288 | + |
| 8289 | + |
8270 | 8290 |
|
8271 | 8291 |
|
8272 | 8292 |
|
|
8279 | 8299 | <ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr"> |
8280 | 8300 |
|
8281 | 8301 | Last update: |
8282 | | - <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="July 27, 2025 06:10:49 UTC">July 27, 2025</span>  |
| 8302 | + <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date" title="November 29, 2025 07:13:18 UTC">November 29, 2025</span>  |
8283 | 8303 |
|
8284 | 8304 | <!-- Tags --> |
8285 | 8305 |
|
@@ -8319,7 +8339,7 @@ <h2 id="algorithm">Algorithm<a class="headerlink" href="#algorithm" title="Perma |
8319 | 8339 | <p>The idea of binary exponentiation is, that we split the work using the binary representation of the exponent.</p> |
8320 | 8340 | <p>Let's write <span class="arithmatex">$n$</span> in base 2, for example:</p> |
8321 | 8341 | <div class="arithmatex">$$3^{13} = 3^{1101_2} = 3^8 \cdot 3^4 \cdot 3^1$$</div> |
8322 | | -<p>Since the number <span class="arithmatex">$n$</span> has exactly <span class="arithmatex">$\lfloor \log_2 n \rfloor + 1$</span> digits in base 2, we only need to perform <span class="arithmatex">$O(\log n)$</span> multiplications, if we know the powers <span class="arithmatex">$a^1, a^2, a^4, a^8, \dots, a^{2^{\lfloor \log n \rfloor}}$</span>.</p> |
| 8342 | +<p>Since the number <span class="arithmatex">$n$</span> has exactly <span class="arithmatex">$\lfloor \log_2 n \rfloor + 1$</span> digits in base 2, we only need to perform <span class="arithmatex">$O(\log n)$</span> multiplications, if we know the powers <span class="arithmatex">$a^1, a^2, a^4, a^8, \dots, a^{2^{\lfloor \log_2 n \rfloor}}$</span>.</p> |
8323 | 8343 | <p>So we only need to know a fast way to compute those. |
8324 | 8344 | Luckily this is very easy, since an element in the sequence is just the square of the previous element.</p> |
8325 | 8345 | <div class="arithmatex">$$\begin{align} |
@@ -8508,7 +8528,7 @@ <h2 id="practice-problems">Practice Problems<a class="headerlink" href="#practic |
8508 | 8528 |
|
8509 | 8529 | <ul class="metadata page-metadata" data-bi-name="page info" lang="en-us" dir="ltr"> |
8510 | 8530 | <span class="contributors-text">Contributors:</span> |
8511 | | - <ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/jakobkogler" title="jakobkogler" data-bi-name="contributorprofile" target="_blank">jakobkogler</a> (41.95%)</li><li><a href="https://github.com/gabrielsimoes" title="gabrielsimoes" data-bi-name="contributorprofile" target="_blank">gabrielsimoes</a> (17.98%)</li><li><a href="https://github.com/tcNickolas" title="tcNickolas" data-bi-name="contributorprofile" target="_blank">tcNickolas</a> (11.24%)</li><li><a href="https://github.com/back2sqr1" title="back2sqr1" data-bi-name="contributorprofile" target="_blank">back2sqr1</a> (5.99%)</li><li><a href="https://github.com/RodionGork" title="RodionGork" data-bi-name="contributorprofile" target="_blank">RodionGork</a> (5.62%)</li><li><a href="https://github.com/Electron1997" title="Electron1997" data-bi-name="contributorprofile" target="_blank">Electron1997</a> (3.0%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (2.62%)</li><li><a href="#" title="shark_s" data-bi-name="contributorprofile" target="_blank">shark_s</a> (2.25%)</li><li><a href="https://github.com/Morass" title="Morass" data-bi-name="contributorprofile" target="_blank">Morass</a> (1.87%)</li><li><a href="https://github.com/turfaa" title="turfaa" data-bi-name="contributorprofile" target="_blank">turfaa</a> (1.87%)</li><li><a href="https://github.com/roundspecs" title="roundspecs" data-bi-name="contributorprofile" target="_blank">roundspecs</a> (1.5%)</li><li><a href="https://github.com/wangwillian0" title="wangwillian0" data-bi-name="contributorprofile" target="_blank">wangwillian0</a> (0.75%)</li><li><a href="https://github.com/arjunUpatel" title="arjunUpatel" data-bi-name="contributorprofile" target="_blank">arjunUpatel</a> (0.37%)</li><li><a href="https://github.com/snymm2" title="snymm2" data-bi-name="contributorprofile" target="_blank">snymm2</a> (0.37%)</li><li><a href="https://github.com/PAndaContron" title="PAndaContron" data-bi-name="contributorprofile" target="_blank">PAndaContron</a> (0.37%)</li><li><a href="https://github.com/rskbansal" title="rskbansal" data-bi-name="contributorprofile" target="_blank">rskbansal</a> (0.37%)</li><li><a href="https://github.com/zhangdavid275" title="zhangdavid275" data-bi-name="contributorprofile" target="_blank">zhangdavid275</a> (0.37%)</li><li><a href="https://github.com/ahmedibrahim404" title="ahmedibrahim404" data-bi-name="contributorprofile" target="_blank">ahmedibrahim404</a> (0.37%)</li><li><a href="https://github.com/wikku" title="wikku" data-bi-name="contributorprofile" target="_blank">wikku</a> (0.37%)</li><li><a href="https://github.com/algmyr" title="algmyr" data-bi-name="contributorprofile" target="_blank">algmyr</a> (0.37%)</li><li><a href="https://github.com/vatsalsharma376" title="vatsalsharma376" data-bi-name="contributorprofile" target="_blank">vatsalsharma376</a> (0.37%)</li></ul> |
| 8531 | + <ul class="contributors" data-bi-name="contributors"><li><a href="https://github.com/jakobkogler" title="jakobkogler" data-bi-name="contributorprofile" target="_blank">jakobkogler</a> (41.95%)</li><li><a href="https://github.com/gabrielsimoes" title="gabrielsimoes" data-bi-name="contributorprofile" target="_blank">gabrielsimoes</a> (17.98%)</li><li><a href="https://github.com/tcNickolas" title="tcNickolas" data-bi-name="contributorprofile" target="_blank">tcNickolas</a> (11.24%)</li><li><a href="https://github.com/back2sqr1" title="back2sqr1" data-bi-name="contributorprofile" target="_blank">back2sqr1</a> (5.99%)</li><li><a href="https://github.com/RodionGork" title="RodionGork" data-bi-name="contributorprofile" target="_blank">RodionGork</a> (5.62%)</li><li><a href="https://github.com/Electron1997" title="Electron1997" data-bi-name="contributorprofile" target="_blank">Electron1997</a> (3.0%)</li><li><a href="https://github.com/adamant-pwn" title="adamant-pwn" data-bi-name="contributorprofile" target="_blank">adamant-pwn</a> (2.25%)</li><li><a href="#" title="shark_s" data-bi-name="contributorprofile" target="_blank">shark_s</a> (2.25%)</li><li><a href="https://github.com/Morass" title="Morass" data-bi-name="contributorprofile" target="_blank">Morass</a> (1.87%)</li><li><a href="https://github.com/turfaa" title="turfaa" data-bi-name="contributorprofile" target="_blank">turfaa</a> (1.87%)</li><li><a href="https://github.com/roundspecs" title="roundspecs" data-bi-name="contributorprofile" target="_blank">roundspecs</a> (1.5%)</li><li><a href="https://github.com/wangwillian0" title="wangwillian0" data-bi-name="contributorprofile" target="_blank">wangwillian0</a> (0.75%)</li><li><a href="https://github.com/harsh-1806" title="harsh-1806" data-bi-name="contributorprofile" target="_blank">harsh-1806</a> (0.37%)</li><li><a href="https://github.com/arjunUpatel" title="arjunUpatel" data-bi-name="contributorprofile" target="_blank">arjunUpatel</a> (0.37%)</li><li><a href="https://github.com/snymm2" title="snymm2" data-bi-name="contributorprofile" target="_blank">snymm2</a> (0.37%)</li><li><a href="https://github.com/PAndaContron" title="PAndaContron" data-bi-name="contributorprofile" target="_blank">PAndaContron</a> (0.37%)</li><li><a href="https://github.com/rskbansal" title="rskbansal" data-bi-name="contributorprofile" target="_blank">rskbansal</a> (0.37%)</li><li><a href="https://github.com/zhangdavid275" title="zhangdavid275" data-bi-name="contributorprofile" target="_blank">zhangdavid275</a> (0.37%)</li><li><a href="https://github.com/ahmedibrahim404" title="ahmedibrahim404" data-bi-name="contributorprofile" target="_blank">ahmedibrahim404</a> (0.37%)</li><li><a href="https://github.com/wikku" title="wikku" data-bi-name="contributorprofile" target="_blank">wikku</a> (0.37%)</li><li><a href="https://github.com/algmyr" title="algmyr" data-bi-name="contributorprofile" target="_blank">algmyr</a> (0.37%)</li><li><a href="https://github.com/vatsalsharma376" title="vatsalsharma376" data-bi-name="contributorprofile" target="_blank">vatsalsharma376</a> (0.37%)</li></ul> |
8512 | 8532 | </ul> |
8513 | 8533 |
|
8514 | 8534 | </article> |
|
0 commit comments