Write a Haskell function numberOfPalindromicSemiPrimes :: Int -> Int that takes an integer

Exercise 4: Distinct powers
Consider all integer combinations of a
b
for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
2
2 = 4, 23 = 8, 24 = 16, 25 = 32
3
2 = 9, 33 = 27, 34 = 81, 35 = 243
4
2 = 16, 43 = 64, 44 = 256, 45 = 1024
5
2 = 25, 53 = 125, 54 = 625, 55 = 3125
If they are placed in numerical order, with any repeats removed, we get the following list:
[4, 8, 9, 16, 25, 27, 32, 64, 81, 125, 243, 256, 625, 1024, 3125]
Write a Haskell function distinct Powers :: Int -> Int -> Int that takes as its input two
positive integers m and n, and produces the number of distinct terms in the sequence generated by
a
b
for 2 ≤ a ≤ m and 2 ≤ b ≤ n. So distinct Powers 5 5 should yield 15. You may assume that the
values of m and n are at least 2 and at most 1000.
The computation of distinct Powers 100 1000 should not take longer than two seconds.
Exercise 5: Palindromic Semi-primes
We call a positive integer n palindromic if reversing its digits yields the same number. For example,
123321 is palindromic, while the number 123 clearly is not.
We call a positive integer n a semi-prime if it can be written as the product of two prime numbers.
For example, 26 = 2 × 13 and 25 = 5 × 5 are semi-primes, while 27 = 3 × 3 × 3 is not.
Write a Haskell function number  Of PalindromicSemiPrimes :: Int -> Int that takes an integer
n (where 1 ≤ n < 108
), and produces as its output the number of palindromic semi-primes x with
1 ≤ x ≤ n.
For example, numberOfPalindromicComposites 100 yields 7 (=length [4,6,9,22,33,55,77].
The time to compute numberOfPalindromicSemiPrimes 99999999 should not exceed two seconds.
Exercise 6: Last n Digits
Write a Haskell function lastDigits :: Integer -> Int -> [Integer] such that lastDigits n d
yields the list of the last d decimal digits of the number Pn
k=1 k
k
. For example, the call lastDigits
10 10 should yield the list [0,4,0,5,0,7,1,3,1,7], since 11 + 22 + .. + 1010 = 10405071317. The
time to compute lastDigits (10^5) 10 using ghci should not exceed two seconds.
Exercise 7: Factorial sums
Define f(n) as the sum of the factorials of the digits of n.
For example, f(342) = 3! + 4! + 2! = 32.
Define sf(n) as the sum of the digits of f(n). So sf(342) = 3 + 2 = 5.
Define g(i) to be the smallest positive integer n such that sf(n) = i. Though sf(342) is 5, sf(25)
is also 5, and it can be verified that g(5) is 25.
Define sg(i) as the sum of the digits of g(i). So sg(5) = 2 + 5 = 7.