Mar:23(Mon)
Please do exercises in teams of two. Doing so garners 5% extra credit.
Show intermediate steps/explanations for obtaining answers.
exponentiation(a,e)
for the invocation exponentiation(3,11):
int exponentiation(int a, int e) { // a := , e :=
int result = 1; // result :=
int sqrrep = a; // sqrrep :=
while ( e > 0 ) { // ( > 0) :=
if ( e % 2 == 1 ) // ( % 2 == 1) := ( == 1) :=
result = result * sqrrep; // result := ( * ) :=
sqrrep = sqrrep * sqrrep; // sqrrep := ( * ) :=
e = e/2; // e := ⌊/2⌋ := ⌊⌋ :=
}
while ( e > 0 ) { // ( > 0) :=
if ( e % 2 == 1 ) // ( % 2 == 1) := ( == 1) :=
result = result * sqrrep; // result := ( * ) :=
sqrrep = sqrrep * sqrrep; // sqrrep := * :=
e = e/2; // e := ⌊/2⌋ := ⌊⌋ :=
}
while ( e > 0 ) { // ( > 0) :=
if ( e % 2 == 1 ) // ( % 2 == 1) := ( == 1) :=
result = result * sqrrep;
sqrrep = sqrrep * sqrrep; // sqrrep := ( * ) :=
e = e/2; // e := ⌊/2⌋ := ⌊⌋ :=
}
while ( e > 0 ) { // ( > 0) :=
if ( e % 2 == 1 ) // ( % 2 == 1) := ( == 1) :=
result = result * sqrrep; // result := ( * ) :=
sqrrep = sqrrep * sqrrep; // sqrrep := ( * ) :=
e = e/2; // e := ⌊/2⌋ := ⌊⌋ :=
}
while ( e > 0 ) { // ( > 0) :=
return result; // return
}
Show an 'algorithm trace' like that
for the invocation exponentiation(10,13).
(Feel free to simply copy the above material (HTML)
and change details such as what numbers are in the spaces.
If you do this, you might need to adjust the sizes of the spaces.)
modular_exponentiation(a,e,m)
for the
invocation modular_exponentiation(7,13,17).
Acknowledgement:
Some of the following exercises are derived from Richard Johnsonbaugh.
modular_exponentiation()
is the fact that
for any integers x and y,
and for any positive integer m,
(x*y) mod m == ((x mod m)*(y mod m)) mod m.
Similarly,
(x+y) mod m == ((x mod m)+(y mod m)) mod m
(for any integers x and y
and for any positive integer m).
f13(y) := ((y mod 7) + (⌊(y-1)/4⌋ mod 7) - (⌊(y-1)/100⌋ mod 7) + (⌊(y-1)/400⌋ mod 7)) mod 7
i.e.
f13(y) := ((y mod 7) + (|_(y-1)/4_| mod 7) - (|_(y-1)/100_| mod 7) + (|_(y-1)/400_| mod 7)) mod 7
Show all those intermediate values mod 7.
For example for next year, 2010:
f13(2010) := ((2010 mod 7) + (⌊(2010-1)/4⌋ mod 7) - (⌊(2010-1)/100⌋ mod 7) + (⌊(2010-1)/400⌋ mod 7)) mod 7
:= ((2010 mod 7) + ( 502 mod 7) - ( 20 mod 7) + ( 5 mod 7)) mod 7
:= ( 1 + 5 - 6 + 5 ) mod 7
:= ( 5 ) mod 7
:= 5
For this exercise,
remember to
redo all of the calculations
of f13(y)
which you did previously,
i.e. for all of
the years specified previously.
if complete/thorough prime factorization of a isDetermine the greatest common divisor of each of the following pairs of integers (a,b), explicitly using the above scheme. In each case, you'll need to give the complete/thorough prime factorization of each number (a and b as well as gcd(a,b)).2e2 * 3e3 * 5e5 * 7e7 * ...
and complete/thorough prime factorization of b is2f2 * 3f3 * 5f5 * 7f7 * ...
thengcd(a,b) := 2min(e2,f2) * 3min(e3,f3) * 5min(e5,f5) * ...
x and y have
(and the results)
during performance of
the Euclidean algorithm for gcd(x,y)
applied to the five pairs of integers
specified in
Exercise I above:
* for gcd(56,16): 56, 16, 8, 0; result: 8 * for gcd(65,50): 65, 50, 15, 5, 0; result: 5