% P1
% (i)   10^k = 5^k * 2^k
% (ii)  If m = ceil(log2(5)*k), then m bits  are required to store 5^k 
% (iii) If F = m-1 then in binary
%                  10^k = (1 b1 b2   bF . 0) *2^k
%                       = (1 . b1 b2   bF)  * 2^ (k + F)
% (iv)  If G = ceil(log2(k+F)), then  G is the number of bits required to 
%        represent the exponent.

% Let us compute the F and G values for a range of k-values...
Kvals = (1:100)';                
F = ceil(log2(5)*Kvals)-1;
G = ceil(log2(Kvals+F));
% It is instructive to look at these vectors before
% proceeeding with the problem.

clc
disp(' p   phi(p)')
disp('-----------------')
for p=1:62
    % Bits for mantissa = p-1 so
    MantissaCanHandle = (sum(F<=p-1));  % The number of F values <= p-1
    % Bits for exponent = 63-p
    ExponentCanHandle = (sum(G<=63-p)); % The number of G values <= 63-p
    phi_of_p = min(MantissaCanHandle,ExponentCanHandle);
    fprintf('%3d   %3d\n',p,phi_of_p)
end

% General comments. Review Matlab's ability to do vector operation.
% Make your output readable. 
% The largest machine representable number (for a given p) is irrelvant in
% this problem. For example, if p = 1 then what is the largest power of
% 10 than can be written in the form 1.b * 2^e? Most of you looked at the
% value of 1.1 x 2^62, took the base 10 log and conclude something like
% 10^18. yet, with just one bit for the mantissa we cannot even store 10^1.
% Minus 4 points for going this route.
    