Steply

Calculate 5^40 mod 6

Step by step, with the reason for every step · Powers mod n, last digits · Discrete Math

Step by step

The question

Question: find 5⁴⁰ mod 6.

540 mod 6

5 to the power 40 has 28 digits.

Too big to work out by hand.

540 has 28 digits!

1 Small powers first

Let's make a table of small powers.

Each one is the one before times 5.

We only keep the remainder: the big part never matters.

only the remainder matters

5 to the 1 is 5.

5
5

Then 5 times 5 is 25.

5 × 5 = 25

25 mod 6 is 1.

And so on.

1
1 × 5 = 5
5

2 Find the pattern

At k = 3 we are back to 5.

From here everything repeats.

So the pattern 5, 1 repeats every 2 powers.

repeats every 2: 5, 1, 5, 1, ...

3 Where 40 lands

40 divided by 2: 20 full patterns, and 0 left over.

40 = 2 × 20 + 0

Careful!

Nothing left over means we end at the end of a pattern: the same place as k = 2.

Careful: not k = 0 ✗

So 5 to the 40 is like k = 2: the last one of the pattern.

So 5⁴⁰ mod 6 is 1.

540 mod 6 = 1

4 Check

A computer can work out all 28 digits: 909494, and so on, 0625.

computer: 540 = 909494...0625

Divided by 6, it leaves 1, the same as our pattern.

Right!

÷ 6: remainder 1

Let's look back.

First: small powers first.

Then: find the pattern.

Then: where 40 lands.

Last: check.

Answer
540 mod 6 = 1

Your turn

Try this one yourself, then check:

872 mod 6
Show the answer
8⁷² mod 6 = 4

More from Powers mod n, last digits

The whole lesson: Powers mod n, last digits →