Deceptively Complex

What will the above process output when we pass the input as ( 6 , 4 ) (6, 4) ?

1 2 3 4

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.

2 solutions

Christopher Boo
Sep 22, 2016

The idea is to break down this process into several subprocesses.

Take a look at the bottom right corner. It keeps subtracting 17 from B when B is larger than 17, this will in the end return B m o d 17 B\mod 17 , except when the result is 0, it will return 17.

Now, let's look at the process that starts from Set Counter to 0 \text{Set Counter to 0} . The process after this will be repeated A A times. More precisely, we perform Add B to B \text{Add B to B} for A A times. Add B to B \text{Add B to B} is another way of saying Multiply B by 2 \text{Multiply B by 2} . So the entire process will multiply B B by 2 A 2^A .

Again, the whole process keeps repeating for A = 6 , 5 , 4 , 3 , 2 , 1 A=6,5,4,3,2,1 . Hence, B is multiplied by 2 for 5 + 4 + 3 + 2 + 1 + 0 5+4+3+2+1+0 times. B becomes

B × 2 5 × 2 4 × 2 3 × 2 2 × 2 1 = B × 2 15 = 2 2 × 2 15 = 2 17 B \times 2^5 \times 2^4\times 2^3 \times 2^2 \times 2^1 = B \times 2^{15} = 2^2 \times 2^{15} = 2^{17}

Recall that we keep subtracting 17 17 from B, and we know that a n m o d b = ( a m o d b ) n m o d b a^n\bmod b = (a\bmod b)^n \bmod b , so it doesn't matter if we do the modulo first or multiplication first. Finally, by Fermat's Little Theorem ,

2 17 m o d 17 = 2 . 2^{17}\bmod {17} = \boxed2.

Sharky Kesa
Sep 30, 2016

Here is my Python solution, since Christopher stole my solution :P.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def F(a,b):
    while a>0:
        a=a-1
        counter=0
        while a!=counter:
            counter+=1:
            b=(2*b)%17
    if a=0:
        return b

print (F(6,4))

This outputs 2 2 as the answer. Note: If the output is 0 0 , it should be interpreted as 17 17 .

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...