# COMPUTER PROBLEMS: DAY 4 (1) Write a code to compute a

```COMPUTER PROBLEMS:
DAY 4
(1) Write a code to compute ab mod e via repeated squaring. (Or check that the
code below works for various examples and try and understand how it works)
Example:
&gt;&gt;&gt; modpower(2,100,101)
1
Code:
def modpower(b,e,m):
&quot;&quot;&quot;modpower(b,e,m) = b^e mod m&quot;&quot;&quot;
P = 1
S = b
while e &gt; 0:
r = e%2
e = e/2
if r == 1:
P = P*S % m
S = S*S % m
return P
(2) What is 1431354254365645765686989879879797987 mod 7987987908098? (can you
do it without the code?)
(3) Write a program that computes the Euler phi function of a number n. You
might start by doing this naively (counting all integers from 1 to n − 1 that
are relatively prime to n) and then in a more sophisticated way by using
the prime factorization of n. The formula for computing φ(n) in terms of
prime factorization is available on Wikipedia. Compute φ for n = 1800 and
n = 10403.
(4) Use Fermat’s little theorem to check if 89809099 is prime. How about
75307568412715349903?