%I #21 Nov 13 2016 17:07:03
%S 1,-1,0,1,-1,-1,1,0,1,1,-1,1,-1,-1,0,1,-1,1,1,1,-1,-1,-1,1,-1,0,1,-1,
%T 1,1,-1,-1,-1,-1,1,1,-1,1,0,1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,1,-1,1,1,0,
%U 1,-1,-1,1,1,1,1,-1,1,-1,1,-1,-1,-1,-1,1,1,-1,0,1,1,1,1,-1,1,-1,1,1,-1,-1,1,1,-1,-1,1,-1,1,-1,-1,-1,-1,0,1,-1,-1,1,1,1,1
%N Triangle read by rows in which row n gives Legendre symbol (k,p) for 0<k<=p where p = n-th prime.
%C Row sums = 0. (p,k)==k^((p-1)/2) (mod p). For example, row n=4 of the triangle (for the 4th prime p = 7) reads: 1,1,-1,1,-1,-1,0 because 1^3==1, 2^3==1, 3^3==-1, 4^3==1, 5^3==-1, 6^3==-1, 7^3==0 (mod 7). - _Geoffrey Critzer_, Apr 18 2015
%H Reinhard Zumkeller, <a href="/A097343/b097343.txt">Rows n = 2..75 of triangle, flattened</a>
%H Haskell for Math, <a href="https://github.com/algal/projecteuler/blob/master/haskellformath/NumberTheoryFundamentals.hs">Number Theory Fundamentals</a>
%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Legendre_symbol">Legendre symbol</a>
%F (p, p)=0, all others are +- 1.
%e 1,-1,0 ; # A102283
%e 1,-1,-1,1,0; # A080891
%e 1,1,-1,1,-1,-1,0; # A175629
%e 1,-1,1,1,1,-1,-1,-1,1,-1,0; # A011582
%p with(numtheory):
%p T:= n-> (p-> seq(jacobi(k, p), k=1..p))(ithprime(n)):
%p seq(T(n), n=2..15); # _Alois P. Heinz_, Apr 19 2015
%t Flatten[ Table[ JacobiSymbol[ Range[ Prime[n]], Prime[n]], {n, 2, 8}]]
%o (Haskell)
%o a097343 n k = a097343_tabf !! (n-2) !! (k-1)
%o a097343_row n = a097343_tabf !! (n-2)
%o a097343_tabf =
%o map (\p -> map (flip legendreSymbol p) [1..p]) $ tail a000040_list
%o legendreSymbol a p = if a' == 0 then 0 else twoSymbol * oddSymbol where
%o a' = a `mod` p
%o (s,q) = a' `splitWith` 2
%o twoSymbol = if (p `mod` 8) `elem` [1,7] || even s then 1 else -1
%o oddSymbol = if q == 1 then 1 else qrMultiplier * legendreSymbol p q
%o qrMultiplier = if p `mod` 4 == 3 && q `mod` 4 == 3 then -1 else 1
%o splitWith n p = spw 0 n where
%o spw s t = if m > 0 then (s, t) else spw (s + 1) t'
%o where (t', m) = divMod t p
%o -- See link. _Reinhard Zumkeller_, Feb 02 2014
%Y See A226520 for another version.
%Y Cf. A068717.
%K sign,tabf
%O 2,1
%A _Robert G. Wilson v_, Aug 02 2004