Tricki
a repository of mathematical know-how
Add article
Navigate
Tags
Search
Forums
Help
Top level
›
Different kinds of Tricki article
›
Front pages for different areas of mathematics
›
Number theory front page
›
Computational number theory front page
View
Edit
Revisions
To work out powers mod n, use repeated squaring
Title:
*
Area of mathematics:
*
A comma-separated list of areas of mathematics to which this article applies. Use ">" to tag in a subcategory. Example: Analysis > Harmonic analysis, Combinatorics
Keywords:
A comma-separated list of keywords associated with this article. Example: free group
Used in:
A comma-separated list of examples of where this technique is used. Example: Cauchy-Schwarz inequality
Parent articles:
Order
-1
0
1
-1
0
1
Body:
[QUICK DESCRIPTION] A fact of fundamental importance in computational number theory is that calculating $a^r$ mod $n$ can be done efficiently on a computer. The reason is simple: by repeatedly squaring $a$, one can work out $a^2$, $a^4$, $a^8$, ... and then other powers $a^r$ can be calculated by taking products chosen according to the binary expansion of $r$. [PREREQUISITES] Modular arithmetic [EXAMPLE] One example is enough to give the idea. Let us work out $3^{37}$ mod $53$. First, we repeatedly square $3$ mod $53$ until we have worked out $3^{2^k}$ for every $k$ such that $2^k\leq 37$. We get $3^2=9$; $3^4=9^2=81\equiv 28$; $3^8\equiv 28^2=784\equiv -11$ (because $15\times 53=795$); $3^{16}\equiv 121\equiv 15$; $3^{32}\equiv 225\equiv 13$. Next, we observe that $37=32+4+1$. Therefore, [maths]3^{37}\equiv 13\times 28\times 3=13\times 84\equiv 13\times 31=403\equiv 32.[/maths] [GENERAL DISCUSSION] This algorithm is considered efficient because the time it takes depends polynomially on the numbers of digits of $a$, $r$ and $n$. For instance, the number of steps taken by long multiplication of two $k$-digit numbers is roughly proportional to $k^2$ (and there are quicker methods that use the [[w:fast Fourier transform]]), and the number of multiplications we need to do in the above calculation is proportional to $\log r$, which is proportional to the number of digits of $r$. If we reduce mod $n$ every time we multiply two numbers together, then the numbers we have to multiply are always smaller than $n$. And reduction mod $n$ can also be done in time polynomial in the number of digits of the number to be reduced, which will always be at most $n^2$ and will therefore have at most twice as many digits as $n$.
This is a stub
A stub is an article that is not sufficiently complete to be interesting.
Notifications
File attachments
Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
Attach new file:
Images are larger than
640x480
will be resized. The maximum upload size is
1 MB
. Only files with the following extensions may be uploaded:
jpg jpeg gif png svg
.
Revision information
Log message:
An explanation of the additions or updates being made to help other authors understand your motivations.
Search this site:
Recent articles
View a list of all articles.
Littlewood-Paley heuristic for derivative
Geometric view of Hölder's inequality
Diagonal arguments
Finding an interval for rational numbers with a high denominator
Try to prove a stronger result
Use self-similarity to get a limit from an inferior or superior limit.
Prove a consequence first
Active forum topics
Plenty of LaTeX errors
Tutorial
A different kind of article?
Countable but impredicative
Tricki Papers
more
Recent comments
I don't think this statement
choice of the field
Incorrect Image
Article classification
Higher dimensional analogues
more