m=input('What is the modulus m? ') sqcount=zeros(m,1); diffsqcount=zeros(m-1,1); squares=[]; for i=1:m j=mod((i-1)*(i-1),m); % find the squares of 0,1,...,m-1 if(sqcount(j+1)==0) squares=[squares j]; % keep in a list if this square is not previously found end sqcount(j+1)=sqcount(j+1)+1; % increment the appropriate counter end square_count=[(0:m-1)' sqcount] % display summary of how often each square occurs for i=2:length(squares) % the first square is 0: we don't use it for j=2:length(squares) if(i==j) else diffsq=mod(squares(i)-squares(j),m); diffsqcount(diffsq)=diffsqcount(diffsq)+1; % increment the appropriate counter end end end difference_count=[(1:m-1)',diffsqcount] %display summary of how often each non-zero difference occurs