brucejin said:
What is the remainder when 2^87 +3 is divided by 7?
How to start? 2^87 is a huge number. Do I have to calculate it?
Thanks.
No.
The key insight for this kind of question is that
"remainder when A x B is divided by Z"
is the same as
"remainder when (remainder when A is divded by Z) x (remainder when B is divided by Z) is divided by Z"
Let me make this slightly less confusing with an example...
67 x 23 = 1541. When this is divided by 15, the remainder is 11. But we didn't have to multiply the numbers out to discover this.
Instead :
* 67, when divided by 15, gives a remainder of 7.
* 23, when divided by 15, gives a remainder of 8.
* 7 x 8 = 56.
* 56, when divided by 15, gives a remainder of 11, just like 1541 does.
A similar rule applies when you add numbers : The remainder when 67+23 is divided by 15 can be worked out without actually adding 67 and 23, just by adding their remainders instead.
Look up
Modular Arithmetic on the net.
Now, I'll do a similar question to yours. I'll find the remainder when 5^107 is divided by 13.
* First, I'll note that 5x5x5x5 = 13x48 + 1. So if I divide 5^4 by 13, the remainder is 1.
* Next, I'll note that 107 = 104+3, so 5^107 = 5^104 x 5^3
* Next, I'll note that 5^104 = (5^4)^26.
* The remainder when I divide 5^4 by 13 is 1, so if I divide (5^4)^26 by 13, the remainder is 1x1x1x1x...x1 = 1^26 = 1.
* So, the remainder when I divide 5^107 by 13 is the same as if I divide 1x125 by 13, that is, 8.
Just to check, I'll use some software to work it out the hard way...
Code:
$ maxima
Maxima 5.12.99rc2 [url]http://maxima.sourceforge.net[/url]
Using Lisp CLISP 2.41 (2006-10-13)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(%i1) 5^107;
(%o1)
616297582203915472977912941627176741932192527428924222476780414581298828125
(%i2) mod(%,13);
(%o2) 8
and again...
Code:
$ python
Python 2.4.3 (#1, May 24 2008, 13:57:05)
[GCC 4.1.2 20070626 (Red Hat 4.1.2-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> pow(5,107) % 13;
8L
>>>