function m=mat(p,k)
q=zeros(p*p,1);
q(1)=k;
for i=1:(p*p-1)
 q(i+1)=floor(q(i)/2);
end 
m=zeros(p,p);
for i=0:(p-1)
 for j=1:p
  m(i+1,j)=(-1)^q(p*i+j);
 end
end

