Nearly a thousand

Find the last 3 digits of 7 9999 {7}^{9999} .


The answer is 143.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Mathh Mathh
Aug 18, 2014

gcd ( 7 , 1000 ) = 1 \gcd(7,1000)=1 , thus we can use Euler's theorem .

7 9999 7 9999 m o d ϕ ( 1000 ) 7 9999 m o d 400 7 1 7^{9999}\equiv 7^{9999 \mod {\phi(1000)}}\equiv 7^{9999\mod {400}}\equiv 7^{-1}

Two ways to continue:

1 7 1 143 7 143 143 1001 143 1 143 ( m o d 1000 ) \equiv \frac{1}{7}\equiv \frac{1\cdot 143}{7\cdot 143}\equiv \frac{143}{1001}\equiv \frac{143}{1}\equiv \boxed {143}\pmod{\!1000}

1 7 1001 7 143 ( m o d 1000 ) \equiv \frac{1}{7}\equiv \frac{1001}{7}\equiv 143\pmod{\! 1000}


Using fractional notation like above makes sense if and only if the denominator is coprime to the modulus.

If the fraction makes sense, its denominator can always be reduced mod the modulus. In this case note gcd ( 7 , 1000 ) = gcd ( 143 , 1000 ) = 1 \gcd(7,1000)=\gcd(143,1000)=1 , so everything makes sense and can be reduced.


In simpler terms: the second method was:

7 x 7 7 9999 7 10000 ( m o d 400 ) 7 0 7x\equiv 7\cdot 7^{9999}\equiv 7^{10000\pmod{\! 400}}\equiv 7^0

\equiv 1\equiv 1001\stackrel{:7}\iff x\equiv 143\pmod{\! 1000}

The first method was:

7x\equiv \cdots\equiv 1\stackrel{\cdot 143}\iff 1001x\equiv x\equiv 143\pmod{\! 1000}

7 ϕ ( 1000 ) {7}^{\phi(1000)} = 1 mod 1000

7 400 {7}^{400} = 1 mod 1000

7 10000 {7}^{10000} = 1 mod 1000

7 9999 {7}^{9999} = 1001/7 mod 1000

7 9999 {7}^{9999} = 143 mod 1000

Although you have done the same, but I am just sharing it in a 'simple' form, I think.

Hey, @mathh mathh do you know what to do when (10^n + 1) is a prime or not divisible by the number(here, 7)? I read in A. Engel's book about it but I didn't get it.

Kartik Sharma - 6 years, 9 months ago

Log in to reply

You just add 1000 1000 's, like 1001 , 2001 , 3001 1001, 2001, 3001 , etc., until the number is divisible by 7 7 .

My method is simple given you have in mind that the denominator can't be simplified when it is not coprime to the modulus. This is the only rule, but isn't difficult to forget when working. In our example we couldn't scale anything by an even number or a multiple of 5 5 .

mathh mathh - 6 years, 9 months ago

Log in to reply

Thank You!

Kartik Sharma - 6 years, 9 months ago

Log in to reply

@Kartik Sharma @Kartik Sharma In case adding 1000 1000 's doesn't help (this can easily happen when all the numbers are big; when they're small, because of the law of small numbers we have that they're often easily simplifiable), we can usually use the Extended Euclidean algorithm, which will almost always help. See my response to Rishabh Jain.

mathh mathh - 6 years, 9 months ago

I didnt understand the last few parts. :/

Jayakumar Krishnan - 6 years, 9 months ago

Log in to reply

If the text under the line is not fully understandable, then sorry - I wanted to edit it to make it more clear, but brilliant doesn't seem to let me edit it.

Anyway, what it's saying is just that you must have the denominator and the modulus coprime if you want to reduce the denominator using the modulus. That's the only restriction if you're working with fractions.

E.g.

1 7 × 3 3 21 3 1 3 ( m o d 10 ) \frac{1}{7}\stackrel{\times 3}\equiv\frac{3}{21}\equiv \frac{3}{1}\equiv \boxed{3}\pmod {10}

But you couldn't have scaled it by 2 2 , since gcd ( 2 , 10 ) = 2 1 \gcd(2,10)=2\neq 1 .

mathh mathh - 6 years, 9 months ago

what should we do if it is 7 9996 {7}^{9996}

Rishabh Jain - 6 years, 9 months ago

Log in to reply

In this case, as you can see, we'd need to find 1 7 4 1 401 ( m o d 1000 ) \frac{1}{7^4}\equiv \frac{1}{401}\pmod {1000}

Now, having modulus as big as 1000 1000 , solving this without using the Extended Euclidean Algorithm would be quite tough. In this problem's case, we were very lucky that 7 1001 7\mid 1001 , but we don't really, in your case, have 7 4 1001 7^4\mid 1001 or 2001 2001 or anything similar, so it's quite tough.

To find the modular multiplicative inverse of 401 401 modulo 1000 1000 (which exists since gcd ( 1000 , 401 ) = 1 \gcd(1000,401)=1 ), we can use the Extended Euclidean Algorithm.

1000 ( 160 ) + 401 ( 399 ) = 1 1000(160)+401(-399)=1

Hence 1 401 399 601 ( m o d 1000 ) \frac{1}{401}\equiv -399\equiv \boxed{601}\pmod {1000} .

The Extended Euclidean Algorithm will find you the inverse of any number modulo another that is coprime to it (if not coprime, the inverse does not exist. Always scale the fractions by a number coprime to the modulus).

mathh mathh - 6 years, 9 months ago

Log in to reply

Very nicely explained mathh mathh .. Loved ur solution.. :)

Ayush Garg - 6 years, 2 months ago

its my doubt since a long time that how can we calculate the numbers equal to or less than N which are co-prime to N plz can u explain @mathh mathh

sakshi rathore - 5 years, 11 months ago

Log in to reply

@sakshi rathore Please ask, if you have any questions.

mathh mathh - 5 years, 11 months ago

Log in to reply

our teacher told us that to find the last three digits we have to know the binomial expansion of it is it really necessary ??not any other method @mathh mathh

sakshi rathore - 5 years, 11 months ago

Log in to reply

@Sakshi Rathore @sakshi rathore Well, above answer found the last three digits of 7 9999 7^{9999} without using Binomial theorem.

There are many methods of finding the last three digits of a b a^b . One of them is using Euler's theorem (or the stronger Carmichael function ), like I did above. Read the end of my answer for a simplified solution.

Sometimes Euler's theorem or Carmichael function is enough, like it was in my answer. If not, then after reducing, you can use Binomial theorem, especially in the following cases:

1) If a = 10 k ± 1 a=10k\pm 1 , then

a b ( ± 1 + 10 k ) b ( ± 1 ) b + ( b 1 ) ( ± 1 ) ( 10 k ) + ( b 2 ) ( ± 1 ) ( 100 k ) ( m o d 1000 ) a^b\equiv (\pm 1+10k)^b\equiv (\pm 1)^b+\binom{b}{1}(\pm 1)(10k)+\binom{b}{2}(\pm 1)(100k)\,\pmod{\! 1000}

2) If (1) can't be used, then if a = 5 k ± 1 a=5k\pm 1 , then

a b ( ± 1 + 5 k ) b ( ± 1 ) b + ( b 1 ) ( ± 1 ) ( 5 k ) + ( b 2 ) ( ± 1 ) ( 25 k ) ( m o d 125 ) a^b\equiv (\pm 1+5k)^{b}\equiv (\pm 1)^b+\binom{b}{1}(\pm 1)(5k)+\binom{b}{2}(\pm 1)(25k)\pmod{\! 125}

a b m o d 8 a^b\bmod 8 is easy to calculate. Then use Chinese Remainder theorem .

Never forget you can use Chinese Remainder theorem, Euler's theorem. It makes some problems extremely simple. E.g., 12 6 891 1 ( m o d 125 ) 126^{891}\equiv 1\,\pmod{\! 125} and 12 6 891 0 ( m o d 8 ) 126^{891}\equiv 0\,\pmod{\! 8} , so by Chinese Remainder theorem the last three digits of 12 6 891 126^{891} are 376 376 . Another example: 45 3 10 1 99 45 3 10 1 99 ( m o d 100 ) 453 ( m o d 125 ) 453^{101^{99}}\equiv 453^{101^{99}\pmod{\! 100}}\equiv 453\pmod{\! 125} and 45 3 10 1 99 45 3 10 1 99 ( m o d 4 ) 453 ( m o d 8 ) 453^{101^{99}}\equiv 453^{101^{99}\pmod{\! 4}}\equiv 453\pmod{\! 8} , so 45 3 10 1 99 453 ( m o d 1000 ) 453^{101^{99}}\equiv 453\pmod{\! 1000} . So you don't always need Binomial Theorem - never forget Chinese Remainder theorem, Euler's theorem (sometimes Carmichael function).

mathh mathh - 5 years, 11 months ago

Log in to reply

@Mathh Mathh oh thank you sir for explaining so well

sakshi rathore - 5 years, 11 months ago

@sakshi rathore I think you want to find ϕ ( 1000 ) \phi(1000) ?

Let's calculate ϕ ( n ) \phi(n) . Let n = p 1 α 1 p 2 α 2 p k α k n=p_1^{\alpha_1}p_2^{\alpha_2}\cdots p_k^{\alpha_k} (remember Fundamental theorem of arithmetic ).

Below formula can be proved:

ϕ ( n ) = ϕ ( p 1 α 1 p 2 α 2 p k α k ) = ( p 1 α 1 p 1 α 1 1 ) ( p k α k p k α k 1 ) \phi(n)=\phi\left(p_1^{\alpha_1}p_2^{\alpha_2}\cdots p_k^{\alpha_k}\right) =\left(p_1^{\alpha_1}-p_1^{\alpha_1-1}\right)\cdots \left(p_k^{\alpha_k}-p_k^{\alpha_k-1}\right)

Another formula (above formula written in a different way):

ϕ ( p 1 α 1 p 2 α 2 p k α k ) = n ( 1 1 p 1 ) ( 1 1 p k ) \phi\left(p_1^{\alpha_1}p_2^{\alpha_2}\cdots p_k^{\alpha_k}\right) =n\left(1-\frac{1}{p_1}\right)\cdots \left(1-\frac{1}{p_k}\right)

So you can just use the formulas instead of searching for all the numbers 1000 \le 1000 coprime to 1000 1000 .

ϕ ( 1000 ) = ϕ ( 2 3 5 3 ) = ( 2 3 2 2 ) ( 5 3 5 2 ) = 400 \phi(1000)=\phi\left(2^3\cdot 5^3\right)=\left(2^3-2^2\right)\left(5^3-5^2\right)=400

So there are 400 400 numbers less than or equal to 1000 1000 that are coprime to 1000 1000 .

If you understand Chinese Remainder Theorem, the proof of the formulas is very simple - see Wikipedia .

mathh mathh - 5 years, 11 months ago
Saket Sharma
Sep 19, 2014

Just observation!

Consider 7^{N}.

Unit place digit has a cycle of 4: 7, 9, 3, 1, 7, 9, 3, 1, ...

Tens place digit has a cycle of 4: 0, 4, 4, 0, 0, 4, 4, 0, ...

Hundredth place digit has a cycle of 20:

0, 0, 3, 4, 8, 6, 5, 8, 6, 2, 7, 2, 4, 8, 9, 6, 2, 4, 1, 0,

0, 0, 3, 4, 8, 6, ...

Now, 100 or 1000 or 10000 etc. are all divisible by 20 (and therfore by 4 as well).

Hence, for each of N = 99, 999, 9999, 99999, etc

7^{N} ends in 143 .

Girija Lenka
Mar 12, 2015

First of all, 7 and 10 are relatively prime, so Euler's theorem applies. You are essentially wanting 7^9999 modulo 1000. Now, the totient function of 1000=2^3 5^3 is (2-1) 2^2 (5-1)^5^2, which is 400. Hence, 7^400=1 mod 1000. So the question is what 9999 is modulo 400. Clearly, it is -1. So what you really want is 7^(-1) mod 1000. In other words, you want an x so that 7x=1 mod 1000. But, it turns out that 7 11 13=1001 is 1 mod 1000, so x=11*13=143.

Thus, the last 3 digits of 7^9999 are 143.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...