Are you curious to know the 2017th digit

201 7 201 6 201 5 201 4 3 2 1 \Large 2017^{2016^{2015^{2014^{\cdot^{\cdot^{3^{2^{1}}}}}}}}

What are the last 2017 digits of the decimal representation of the number above?

Submit your answer as the first 4 leftmost digits of this 2017-digit integer.


The answer is 9729.

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.

1 solution

Jesse Nieminen
Feb 8, 2017

From the output of the following Java code, take the first 4 4 digits and get 9729 \boxed{9729} which is the answer.

(Could be optimized further by using Carmichael Lambda Function.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.math.BigInteger;

public class Main3 {

    private static final BigInteger TWO = new BigInteger("2"), FIVE = new BigInteger("5");
    private static BigInteger[] mods = new BigInteger[2016];

    private static BigInteger eulerPhi(BigInteger big) {
        if(big.mod(TWO).signum() == 0) {
            big = big.divide(TWO);
        }
        if(big.mod(FIVE).signum() == 0) {
            big = big.divide(FIVE).multiply(TWO).multiply(TWO);
        }
        return big;
    }

    private static void computeMods() {
        mods[2015] = BigInteger.TEN.pow(2017);
        for (int i = mods.length-2; i >= 0; i--) {
            mods[i] = eulerPhi(mods[i+1]);
        }
    }


    public static void main(String[] args) {
        computeMods();

        BigInteger start = BigInteger.ONE;

        for (int i = 0; i < 2016; i++) {
            start = new BigInteger(""+(i+2)).modPow(start, mods[i]); 
        }

        System.out.println(start);

    }

}

Great When two different methods give the same result it is more interesting.

Mr X - 4 years, 4 months ago

OMG What a beautiful solution.

Rishabh Deep Singh - 4 years ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...