Sunteți pe pagina 1din 25

Dividing Large Numbers and Finding

the Remainder
Some IIM Questions also been inserted giving deep insight into different number theory
problems

Modular Arithmetic
The "mod" operator in computer languages is simply the remainder. For example,
17 mod 3 = 2 ; because 17 / 3 = 5 rem 2 which in turn means 17 = 3 * 5 + 2
Note:

The Set of all Integers can be divided into 3


classes:

There are some tricky issues when negative numbers are used, but that shouldn't ordinarily
be necessary.
In math (number theory), the term is used a little differently. The "modulus" is actually

not the remainder, but the number you are dividing by; and "mod" is not an
operator, but a label telling "in what sense two quantities are considered
congruent, or equal." For example, we would say 17 = 11 (mod 3)

(read as "17 is congruent to 11, modulo 3"), meaning that 17 and 11 both leave the SAME
remainder when divided by 3. You probably won't see this usage if you are only reading
about programming, but it's worth being aware of if you look deeper into the math behind
it.
The notation (mod 100) is common in a branch of mathematics called number theory. It
refers to so-called "modular arithmetic."
When it is taught in school, it is often called "clock arithmetic."
The idea is the same as the one found in "casting out nines," except you will be "casting out
hundreds." The idea is that if you do addition, subtraction, or multiplication, you can discard
multiples of 100 either before or after the operation, or both, and you will get an answer
that differs from the ordinary operation answer only by a multiple of 100.
The notation is as follows:

If m is a positive whole number, and a and b are any whole numbers, then
we write a = b (mod m) if and only if m divides a - b. It is easy to see that:
(1) a = a (mod m).
(2) If a = b (mod m), then b = a (mod m).
(3) If a = b (mod m) and b = c (mod m), then a = c (mod m).
Additive, Divisional, Multiplicative property
(4) If a = b (mod m) and c = d (mod m), then a + c = b + d (mod m).
(5) If a = b (mod m) and c = d (mod m), then a - c = b - d (mod m).
(6) If a = b (mod m) and c = d (mod m), then a * c = b * d (mod m).
You can figure out why it is that when we are only interested in the last two decimal digits
of a whole number, we can work (mod 100).
You can also figure out why -4 = 1996 (mod 100).
Now you can use the facts (1)-(6) (especially (6)) above to compute 1996^1996 (mod 100),
as in the solution to the problem provided with the test.

Finding the Remainder when Large Number is divided


It is easy to compute the remainder left behind upon dividing,
for example, 2100 divided by 3 leaves a remainder of ? using modular arithmetic.
Modular arithmetic is a system of arithmetic in which numbers wrap around, or get reset
once they reach a certain value. You can think of it as arithmetic using a number circle as
opposed to a number line.
Consider a circle having circumference 2 units:

First, notice that if you start at the point marked 0 and move 2 units clockwise, you would
return to the point marked zero. Also note that, if we start at 0, moving 3 units clockwise
and 1 unit anticlockwise will result in reaching the same destination. We represent this fact
using the notation, 31(mod2), which is read as 3 is congruent to 1 modulo 2. This is
equivalent to saying that 3 and one leave the same remainder when divided by 2,
or that (31) is an integral multiple of 2.
Hence, the statement xy(moda) is equivalent to the following statements:
1. xy is an integral multiple of a, and
2. x and y leave the same remainder upon division by a.
Modular arithmetic is very useful because of some of the properties of congruence
relations. If a1b1(modn) and a2b2(modn), then the following properties will hold true.
(a1+a2)(b1+b2)(modn)
(a1a2)(b1b2)(modn)
(a1a2)(b1b2)(modn)
We will find the last property to be particularly useful.

Example 1: Remainder upon dividing 2100 by 3


First, we note that 21(mod3).
Because of the last property, this implies that 2100(1)100(mod3).
Because (1)100=1, the remainder will be 1. This can be verified using Wolfram|Alpha.

Example 2: Remainder upon dividing 72010 by 25


First, we note that 72010=491005. Now, because 491(mod25),
491005(1)1005(mod25)
4910051(mod25)
49100524(mod25)
In the last step, I added 25 to the right side of the congruence. I was able to do so because
of the first property.
Hence, the remainder on dividing 72010 by 25 is 24.

What is the remainder when 7^100 is divided by 13?


Give a general strategy with explanation for this type of problem.
a mod n means the remainder that a leaves when divided by n.
So, for example, 20 mod 13 = -19 mod 13 = 7
(20 and -19 differ by a multiple of 13, namely 39 = 3*13. 7 and -19 differ by 2*13, and so on.
Can you give another number x with x mod 13 = 7 ?), or
another example: 4 mod 3 = -2 mod 3 = 998 mod 3 = 1?
You say "4 is congruent to 1 modulo 3."
When adding and multiplying modulo n, you can always replace a number x by another
number y as long as x is congruent to y modulo n:
(x*y) mod n = (x mod n) * (y mod n).
Example: Compute 11^2 mod 13.
First look at a smaller number.
11 mod 13 = -2 mod 13, because 11-(-2) = 1*13.
Now replace 11 with -2 everywhere:
11^2 mod 13 = (-2)^2 mod 13 = 4 mod 13 = 4.
Thus we conclude that 11^2 mod 13 = 4.
Check: 11^2 = 121 = 4+9*13, so indeed
11^2 and 4 differ by a multiple of 13.

For powers, you use "Fermat's little theorem":

n always divides an-a, or an mod n = a mod n.


(Check some examples! The proof of this is easy with a bit of higher math, but I think it is
over your head now.)
Now back to your problem: 7^100 mod 13 = ?
First we know that 13 divides 7^13-7 = 7*(7^12-1) as above.
13 of course doesn't divide 7, so it divides 7^12-1.
So 7^12 mod 13 = 1 mod 13.
Thus 7^24 mod 13 = (7^12*7^12) mod 13
= (7^12 mod 13)^2
= (1 mod 13)^2 = 1
And 7^36 mod 13 = (7^24*7^12) mod 13 = ... = 1
Can you complete the steps alone? You see this property will hold for ANY multiple of 12.
7^96 mod 13 = 7^(8*12) mod 13 = 1. We are almost there.
So 7^100 mod 13 = 7^96 mod 13 * 7^4 mod 13 = 49^2 mod 13 = ...

(you can surely continue from here alone, hint: 52 = 4*13).


Just make sure that the number at the end lies between 0 and 12.
That number is your solution.

Find the remainder when 44444444 is divided by 9....Help!?


4444 = 4437 + 7
= 9 * 493 + 7
= 7(mod 9)
So, 4444^4444 = 7^7 (mod 9)
This is still a very large number, so finding the remainder upon division by 9 will be difficult.
So lets try to break it down further.
7^7 = 7^6 * 7
= (7^2)^3 * 7
= 49^3 * 7
49 = 45 + 4
=9*5+4
= 4 (mod 9)
So, 49^3 * 7 = 4^3 * 7 (mod 9)
= 64 * 7 (mod 9)
64 = 63 + 1
=9*7+1
= 1 (mod 9)
So, 64 * 7 = 1 * 7(mod 9)
= 7 (mod 9)
So, the remainder you get when you divide 4444^4444 by 9 is 7.

How to find the Last digit of an Exponential number

There is no formula but there is a pattern that will show you how to find the
last digit.
For example "What is the last digit of 7358?"
Suppose that you are going to construct a table with 358 rows and record last digit of the
the 358 powers of 7. Start the table, either using either your calculator or doing the
arithmetic by hand.
Power of 7

Last digit

71

72

73

74

75

76

77

78

79

Notice the pattern of the last digits. They are 7,9,3,1,7,9,3,1,7,9,... The last digit repeats in a
pattern that is 4 digits long, 7,9,3,1.
If you complete the table for 358 rows how many times will this pattern repeat? 358 divided
by 4 is 89 with a remainder of 2 so the pattern will repeat 89 times and then there are two
more rows. These rows then have 7 and 9 in the second column so the last digit of 7 358 is 9.

Question-IIM
For what value of 'n' will the remainder of 351n and 352n be the same when divided by 7?
1. 2
2. 3
3. 6

4. 4
Correct Choice is (2) and the Correct Answer is 3
Explanatory Answer:
When 351 is divided by 7, the remainder is 1.
When 352 is divided by 7, the remainder is 2.
Let us look at answer choice (1), n = 2
When 3512 is divided by 7, the remainder will be 12 = 1.
When 3522 is divided by 7, the remainder will be 22 = 4.
So when n = 2, the remainders are different.
When n = 3,
When 3513 is divided by 7, the remainder will be 13 = 1.
When 3523 is divided by 7, the remainder will be 23 = 8.
As 8 is greater than 7, divide 8 again by 7, the new remainder is 1.
So when n = 3, both 351n and 352n will have the same remainder when divided by 7.

Number Theory : Test of Divisibility Question


Divisibility of a large number

Question
The largest number amongst the following that will perfectly divide 101
1. 100
2. 10,000
3. 100100
4. 100,000
Correct Choice is (2) and Correct Answer is 10,000

100

- 1 is

Explanatory Answer
The easiest way to solve such problems for CAT purposes is trial and error or by back
substituting answers in the choices given.
2

101 = 10201.

101 - 1 = 10200. This is divisible by 100.


3

Similarly try for 101 - 1 = 1030301 - 1 = 1030300.


1

So you can safely conclude that (101 - 1) to (101 - 1) will be divisible by 100.
(101

10

99

- 1) to (101

Therefore, (101

100

- 1) will be divisible by 1000.

- 1) will be divisible by 10,000.

Number Theory : Remainders, Finding Divisors


Remainders of division of different numbers by the same divisor

Question
A number when divided by a divisor leaves a remainder of 24. When twice the original
number is divided by the same divisor, the remainder is 11. What is the value of the divisor?
1. 13
2. 59
3. 35
4. 37
Correct Choice - (4). Correct Answer is 37

Explanatory Answer
Let the original number be 'a'
Let the divisor be 'd'
Let the quotient of the division of a by d be 'x'

Therefore, we can write the relation as


i.e., a = dx + 24

= x and the remainder is 24.

When twice the original number is divided by d, 2a is divided by d.


We know that a = dx + 24. Therefore, 2a = 2dx + 48

The problem states that


leaves a remainder of 11.
2dx is perfectly divisible by d and will therefore, not leave a remainder.
The remainder of 11 was obtained by dividing 48 by d.
When 48 is divided by 37, the remainder that one will obtain is 11.
Hence, the divisor is 37.

Number Theory : Remainders, Divisors


Remainders of division of two different numbers and their sum by the same divisor

Question
When 242 is divided by a certain divisor the remainder obtained is 8. When 698 is divided by
the same divisor the remainder obtained is 9. However, when the sum of the two numbers
242 and 698 is divided by the divisor, the remainder obtained is 4. What is the value of the
divisor?
1. 11
2. 17
3. 13
4. 23
Correct Choice is (3) and Correct Answer is 13

Explanatory Answer
Let the divisor be d.
When 242 is divided by the divisor, let the quotient be 'x' and we know that the remainder is
8.
Therefore, 242 = xd + 8
Similarly, let y be the quotient when 698 is divided by d.
Then, 698 = yd + 9.
242 + 698 = 940 = xd + yd + 8 + 9
940 = xd + yd + 17
As xd and yd are divisible by d, the remainder when 940 is divided by d should have been
17.
However, as the question states that the remainder is 4, it would be possible only when
leaves a remainder of 4.
If the remainder obtained is 4 when 17 is divided by d, then d has to be 13.

Number Theory : Division of Polynomial


Remainders of division of a polynomial

Question
3

What number should be subtracted from x + 4x - 7x + 12 if it is to be perfectly divisible by


x + 3?
1. 42

2. 39
3. 13
4. None of these
Correct Choice is (1) and Correct Answer is 42

Explanatory Answer
According to remainder theorem when
3

, then the remainder is f(-a).

In this case, as x + 3 divides x + 4x - 7x + 12 - k perfectly (k being the number to be


subtracted), the remainder is 0 when the value of x is substituted by -3.
3

i.e., (-3) + 4(-3) - 7(-3) + 12 - k = 0


or -27 + 36 + 21 + 12 = k
or k = 42

Number Theory : Division of factorials, remainders


The highest power of 10 that can divide a factorial. Number of trailing zeroes.

Question
A person starts multiplying consecutive positive integers from 20. How many numbers
should he multiply before the will have result that will end with 3 zeroes?
1. 11
2. 10
3. 6
4. 5
Correct Choice is (3) and correct answer is 6

Explanatory Answer
A number will end in 3 zeroes when it is multiplied by 3 10s.
To get a 10, one needs a 5 and a 2.
Therefore, this person should multiply till he encounters three 5s and three 2s.
20 has one 5 (5 * 4) and 25 has two 5s (5 * 5).
20 has two 2s (5 * 2 * 2) and 22 has one 2 (11 * 2).
Therefore, he has to multiply till 25 to get three 5s and three 2s, that will make three 10s.
So, he has to multiply from 20 to 25 i.e. 6 numbers.

Number Theory : Number of factors


Question
What is the smallest number that has exactly 12 factors?
1. 211
2. 60
3. 120
4. 96
Correct Choice is (2) and Correct Answer is 60

Explanatory Answer

a bc

Number of the form p q r (where p q, r are primer) has (a + 1) (b + 1) (c + 1) factors.


So, if some number has 12 factors (a + 1) (b + 1) (c + 1)should be 12.
12 can be written as
12 or 6 x 2
=> 4 x 3
=> 2 x 2 x 3
If a number has to have 12 factors, it should be in one of the following forms,
p

11

=> 11 + 1 factor

5 1

p q => 6 x 2 = 12 factors
3 2

p q => 4 x 3 = 12 factors
2 1`

p q r => 3 x 2 x 1 = 12 factors
Let us deduce the smallest possible number in each form
p

11

11

=> 2

5 1

3 2

= 2048

p q => 2 x 3 = 96
2

p q => 2 x 3 = 72
2 11

p q r => 2 x 3 x 5 = 60
Smallest number that has exactly 12 factors = 60

Number properties : Prime Numbers


Question
If f(x) is the number of primes less than or equal to x, find the value of f(90) - f(80).
1. 3
2. 2
3. 1

4. 4
Correct Choice is (2) and Correct Answer is 2

Explanatory Answer
f(x) is a prime number < x
f(90) = Number of primes < 90
f(80) = Number of primes < 80
f(90) - f(80) = Number of primes between 80 and 90, both inclusive.
=> The prime numbers between 80 and 90 are 83 and 89.
f(90) - f(80) = 2

Number Theory : Number of Factors


Question
N is the smallest number that has 5 factors. How many factors does (N - 1) have??
a. 2
b. 3
c. 4
d. 5
Correct Choice is (c) and the Correct Answer is 4

Explanatory Answer

A number that has 5 factors has to be of the form p where 'p' is a prime number.
4

The smallest such number is 2 = 16


Therefore, N - 1 = 15.
The factors of 15 are 1, 3, 5, 15.
So, N - 1 has 4 factors.

Number Theory : Remainders of division by 6


Finding remainders when sum of powers of 9 are divided by 6

Question
1

What is the remainder when 9 + 9 + 9 + .... + 9 is divided by 6?>


1. 3
2. 2
3. 0
4. 5
Correct Choice is (3) and Correct Answer is 0

Explanatory Answer

6 is an even multiple of 3. When any even multiple of 3 is divided by 6, it will leave a


remainder of 0. Or in other words it is perfectly divisible by 6.
On the contrary, when any odd multiple of 3 is divided by 6, it will leave a remainder of 3.
For e.g when 9 an odd multiple of 3 is divided by 6, you will get a remainder of 3.
9 is an odd multiple of 3. And all powers of 9 are odd multiples of 3.
Therefore, when each of the 8 powers of 9 listed above are divided by 6, each of them will
leave a remainder of 3.
The total value of the remainder = 3 + 3 + .... + 3 (8 remainders) = 24.
24 is divisible by 6. Hence, it will leave no remainder.
1

Hence, the final remainder when the expression 9 + 9 + 9 + .... + 9 is divided by 6 will be
equal to '0'.

Number Properties : Number of factors


Question
Find the smallest number that has exactly 18 factors.
1. 288
2. 768
3. 180
4. None of the above
Correct Choice is (3) and Correct Answer is 180

Explanatory Answer
Formula for finding the number of factors of a number m is very simple.
a b c

If m can be prime factorized as p q r , m has (a + 1) (b + 1) (c + 1) factors.


Let N be the smallest number that can have 18 factors.
a b c

Let N = p q r (p, q, r being primes)


No of factors = (a + 1) (b + 1) (c + 1) = 18
18 can be written as 18 x 1 => N can be p
The smallest possible number = 2

17

17

18 => 2 x 9 => N = pq
Smallest possible number
8

=> 2 x 3 [smallest prime allotted to high power]


=> 256 x 3 = 768

2 5

18 => 3 x 6 => N = p q
5

Smallest number = 2 x 3
=> 32 x 9 = 288

2 2

18 => 2 x 3 x 3 => N = p q r
2

Smallest number = 2 x 3 x 5
=> 36 x 5 = 180
Smallest possible number overall = 180

What are the last five digits of

7777777^7777777?
The idea is that you want
7777777^7777777 (mod 100000).
As you (correctly) stated, this is the same as
77777^7777777 (mod 100000).
In general, the efficient method for computing a modular exponent
like the one above is to start by repeatedly squaring, and reducing
after each square, recording only the last five digits, like so:
77777^2 = 61729 (mod 100000)
77777^4 = 61729^2 = 69441 (mod 100000)
77777^8 = 69441^2 = 52481 (mod 100000)
etc.
Then you see which powers you need, like so:
77777 = 1 + 16 + 64 + 128 + 256 + 512 + 1024 + 2048 + 8192 + 65536

(This last is the same as writing the exponent in binary.) And then
you multiply together the appropriate powers, reducing mod 100000
after each product, as in
77777^77777 = 77777^1 * 77777^16 * 77777^64 * ....
Oh! Except I forgot that you wanted the exponent 7777777 rather
than 77777. I'll let you convert that one into binary (or a sum of
powers of two). Notice that each squaring and each product can be
done on the ten-digit calculator, since each is multiplying two fivedigit numbers. Then you only record the last five digits, and you go
on.
This technique is known by mathematicians as "modular
exponentiation."

How to Find the Last Digits of a


Positive Power of Two
By Rick Regan (Published October 14th, 2009)
A common exercise in number theory is to find the last digits of a
large power, like 22009, without using a computer. 22009 is a 605-digit
number, so evaluating it by hand is out of the question. So how do
you find its last digits efficiently?
Modular arithmetic, and in particular, modular exponentiation,
comes to the rescue. It provides an efficient way to find the last m
digits of a power, by hand, with perhaps only a little help from a
pocket calculator. All you need to do is compute the power
incrementally, modulo 10m.

In this article, I will discuss three methods all based on modular


exponentiation and the laws of exponents for finding the ending
digits of a positive power of two. The techniques I use are easily
adapted to powers of any number.

1. Ad Hoc Exponentiation
In this method, you reduce a power of two modulo 10m repeatedly
until you get a congruent power, or product of powers, for which the
end digits are known or easily computed. You use your knowledge
of smaller powers of two, in conjunction with the power of a power
and product of powers rules, to set up easier sub problems to solve.
You start by dividing the exponent of 2n by the exponent of a known,
smaller power of two, 2a, getting a quotient q and a remainder r. You
then rewrite 2n as (2a)q 2r.

Finding the Last Digit


Ive categorized two sub methods of the ad hoc method that make it
more systematic when dealing specifically with powers of two. I call
them the powers of two method and the powers of six method.
Powers of Two Method

In the powers of two method, you reduce a power of two by using a


power of two ending in 2. This reduces the problem at each stage to
a smaller power of two, giving the method a recursive feel. The
intermediate powers of two are in effect nested.
For example, lets find the last digit of 22009, using 25 (32) to reduce
the problem at each step:

So

, showing that 22009 ends in 2.

The intermediate results 2405, 281, 217, and 25 are all congruent,
ending in 2. If you recognize this along the way, you can stop. For
example, if you happen to know that 217 is 131,072, you can stop
after the third step.
Any power of two ending in 2 works. Heres how the process goes
when using 29(512):

Using 29, there is one less step, but the arithmetic is slightly harder
(division by 9 instead of division by 5).
Powers of Six Method

In the powers of six method, you reduce a power of two using a


power of two that ends in 6. This introduces powers of six, which
have to be handled separately and combined with the remainder
powers of two. For example, lets do our example with 24 = 16. The
first step would give:

But wait! All powers of six end in 6 (6 times 6 mod 10 is 6, and


around it goes), so we just turned this into a very simple
problem:
.
So, while it doesnt have the elegance of the powers of two method,
the powers of six method is simpler.

Finding the Last Two Digits


The powers of six method does not apply to mod 100, but the
powers of two method does indirectly. Although there is no
power of two that ends in 02, we can use any two-digit ending that is
a power of two; we just convert it to 2yusing the laws of exponents.
Lets go back to our example, 22009. Consulting a table of positive
powers of two, find a power of two that ends in 04; for example,
222 (4,194,304). Lets use this to reduce our problem at each step:

Finding the Last m Digits


For the last m digits, find an m-digit power of two (m digits including
leading zeros) greater than or equal to 2m and convert it to 2y as
above. Of course, the remainders will become larger and larger as
the modulus increases.

2. Successive Squaring
The method of successive squaring, also called repeated squaring
or binary exponentiation, is a very systematic way to do modular
exponentiation. Its a generic four step process applicable to any
base and modulus, but heres how to use it to compute 2n mod
10m specifically:
1. Rewrite 2n so that n is a sum of powers of two (essentially, convert
n to binary).
2. Rewrite 2n using the product of powers rule.
3. Create a list of powers 22i mod 10m, by repeatedly squaring the prior
result.

4. Combine, with multiplication mod 10m, the powers in the list that
make up 2n.
This process is independent of the number of ending digits m,
although you have to deal with bigger and bigger numbers as m
increases.

Example: Find the Last Digit of 22009


Lets use this method to find the last digit of 22009:
1. 22009 = 21024 + 512 + 256 + 128 + 64 + 16 + 8 + 1
2. 22009 = 21024 2512 2256 2128 264 216 28 21
3. Create a list of powers of two raised to powers of two, mod 10:

(I wrote out the whole list for completeness, but it was unnecessary
to go beyond 24. Again, thats because all powers of six end in 6.)
4. Combine the required powers:

Example: Find the Last Two Digits of 22009


Lets use this method to find the last two digits of 22009:
1. 22009 = 21024 + 512 + 256 + 128 + 64 + 16 + 8 + 1
2. 22009 = 21024 2512 2256 2128 264 216 28 21
3. Create a list of powers of two raised to powers of two, mod 100:

(Notice that the powers in this list cycle after a point, so it is not
necessary to compute them all.)
4. Combine the required powers:

(I could have used negative numbers in the intermediate steps to


make the math easier; for example, -4 instead of 96. Both are
congruent mod 100.)

3. Cyclic Powers
In this method, you exploit the fact that the ending m digits of the
positive powers of two repeat in cycles; specifically, cycles of length
45m-1, starting at 2m. Powers of two that differ in their exponents by
45m-1 have the same ending m digits.
There are two ways to use the cycle information, in techniques I call
the table method and the base power method.
Table Method

In the table method, you compute the powers of two mod 10m in
sequence, until the ending digits cycle. You label entries sequentially
starting at m, wrapping around 0 to end at m 1. Ive created tables
for the last one, two, and three ending digits; in other words, tables
for powers of two mod 10, mod 100, and mod 1000.
To find where in the cycle your power 2n falls, compute n mod 45m-1,
or equivalently, find the remainder of n/(45m-1). The last m digits of
2n are the digits in the table with the label corresponding to that
remainder.
For example, lets find the last digit of 22009. The last digit of the
positive powers of two cycles with length 4, and
.
According to the table, a remainder of 1 corresponds to a last digit of
2.
Almost as simply, we can find the last two digits of 22009. The last two
digits of the positive powers of two cycle with length 20,
and
. According to the table, a remainder of 9
corresponds to the ending digits 12.

Finding the Last m Digits


The table method works for any number of ending digits, but beyond
two or three, is impractical. The tables grow large, by a factor of five
for each additional ending digit.

Base Power Method

Every power of two 2n, mod 10m, is congruent to some power of two
in the first instance of the cycle; that is, a power of two between
2m and 2(m + 45m 1 1). You need to determine which power of two in
this range it is what I call thebase power of two and then use
another method to find its ending digits.
You can find the base power of two directly: it is 2m + j, where j is an
offset given by the expression n-m (mod 45m-1).
For example, lets find the last digit of 22009.
, so the
1+0
1
base power of two is 2 = 2 = 2. Trivially, we can see the ending
digit is 2.
For the last two digits of 22009, compute
. The base
2+7
9
power of two is 2 = 2 , which is small enough to compute directly:
512. The last two digits are 12.

Finding the Last m Digits


The base power method works well for any number of ending digits,
assuming n is greater than 45m-1.

Cheating
I said find the last digits without using a computer, right? I wanted to
verify my work, so I used PARI/GP to compute 22009. It took an instant
here it is:
58,784,291,598,041,831,640,721,059,900,297,317,581,942,666,346,
941,194,264,
455,308,125,479,232,583,289,360,069,460,965,699,405,121,019,824
,433,389,516,
158,094,000,492,490,796,188,432,969,007,685,435,732,643,092,034
,554,442,399,
887,360,352,654,923,898,902,974,171,610,618,912,504,957,328,187
,117,386,950,

842,341,026,317,332,718,773,233,103,358,237,779,148,190,179,650
,358,079,135,
564,562,516,081,648,810,332,848,214,481,400,042,754,868,418,296
,221,651,998,
157,278,605,568,219,649,390,953,792,425,227,268,163,704,976,021
,381,769,156,
258,409,778,685,642,966,081,035,151,287,502,869,585,844,829,824
,788,935,390,
157,871,063,324,138,385,197,912,084,049,961,962,094,914,858,370
,754,777,898,
867,719,950,514,578,646,749,211,908,564,621,201,347,904,089,822
,990,746,021,
295,498,658,798,312,326,238,643,788,303,040,512

Summary
The three methods Ive shown are efficient ways to do modular
exponentiation, unlike the straightforward method, which requires
n-1 multiplications to compute 2n mod 10m. The three methods
provide shortcuts to the answer, exploiting knowledge of the laws of
exponents and the cycling of ending digits.
Which method should you use? The ad hoc method is the least
systematic but allows for case-by-case optimization. The method of
successive squaring is the most systematic but may be overkill for
certain problems. Learn all three methods to get a deeper
understanding, then decide which one you like.
For finding the last digit, I like the ad hoc powers of six method. It is
the quickest.

Exercises
For these exercises, use any method you like or all three if youre
feeling ambitious:
1. Find the last digit of 2497

2. Find the last digit of 220000


3. Find the last two digits of 2613
4. Find the last two digits of 2512
5. Find the last three digits of 2129
6. Find the last three digits of 22009

Answers
1. 2
2. 6
3. 92
4. 96
5. 912
6. 512

Q
111.

Find the remainder when (12371^56 + 34)^28 is divided by

Ans 111 = 3*37. Solve the problem for 3 and 37, then combine the
answers.
12371 = -1 (mod 3)
so
12371^56 = (-1)^56
= 1 (mod 3)
Then 12371^56 + 34 = -1 (mod 3), and so
(12371^56 + 34)^28 = (-1)^28 = 1 (mod 3)
Now for the modulus 37,
12371 = 13 (mod 37)

12371^56 = 13^56 (mod 37)


To find 13^56, compute in order 13^i where i = 1, 2, 3, 6, 7, 14, 28,
and 56, by, at each step, either squaring or multiplying by 13. Reduce
modulo 37 after each step. That keeps the numbers small. That gives
you
12371^56 = 16 (mod 37)
Now add 34, and you are back to powers of 13. Notice that you have
13^28 already calculated as the next-to-last step of the previous
computation.
Now find a number less than 111 that is congruent to 33 modulo 37
and congruent to 1 modulo 3, and you'll have your answer.

S-ar putea să vă placă și