Beruflich Dokumente
Kultur Dokumente
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:
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.
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.
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.
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.
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
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'
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.
Question
3
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
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.
Explanatory Answer
a bc
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
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
Explanatory Answer
A number that has 5 factors has to be of the form p where 'p' is a prime number.
4
Question
1
Explanatory Answer
Hence, the final remainder when the expression 9 + 9 + 9 + .... + 9 is divided by 6 will be
equal to '0'.
Explanatory Answer
Formula for finding the number of factors of a number m is very simple.
a b c
17
17
18 => 2 x 9 => N = pq
Smallest possible number
8
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
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."
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.
So
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
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.
(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:
(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:
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.
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.
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
Answers
1. 2
2. 6
3. 92
4. 96
5. 912
6. 512
Q
111.
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)