gap> f:=function(p)
> return 1 + 2* ((p+1)/12 - (1+Legendre(-1,p))/4 - (1+Legendre(-3,p))/3); 
> end;;

gap> f(2^13-1);
1365
gap> f(2^17-1);
21845
