%I #19 Feb 16 2018 04:04:42
%S 1,2,7,14,31,62,113,226,233,466,647,1294,1487,2974,4919,6329,7951,
%T 12658,15902,26329,26833,47737,52658,53623,53666,95474,107246,128959,
%U 135697,142327,271394,284654,715177,1312777,1430354,1474657,2625554
%N a(n) is square mod a(i), i < n.
%C Apparently A034698 is a subsequence and all elements are products of elements of A034698.
%C a(n) is the smallest integer larger than a(n-1) such that all a(i), 1<=i<n, are quadratic residues mod a(n). - _R. J. Mathar_, Jul 27 2015
%p A034791 := proc(n)
%p option remember;
%p local a,wrks ;
%p if n = 1 then
%p 1;
%p else
%p for a from procname(n-1)+1 do
%p wrks := true;
%p for i from 1 to n-1 do
%p if numtheory[quadres](procname(i),a) <> 1 then
%p wrks := false;
%p end if;
%p end do;
%p if wrks then
%p return a;
%p end if;
%p end do:
%p end if;
%p end proc: # _R. J. Mathar_, Jul 27 2015
%t residueQ[n_, k_] := Length[Select[Range[Floor[k/2]], PowerMod[#, 2, k] == n &, 1]] == 1; a[1] = 1; a[n_] := a[n] = For[r = Range[n - 1]; an = a[n - 1] + 1, True, an++, If[AllTrue[r, residueQ[a[#], an] &], Return[an]]]; Table[Print["a(", n, ") = ", a[n]]; a[n], {n, 1, 37}] (* _Jean-François Alcover_, Feb 16 2018 *)
%o (Haskell)
%o a034791 n = a034791_list !! (n-1)
%o a034791_list = 1 : f [2..] [1] where
%o f (x:xs) ys | and $ map (flip isSquMod x) ys = x : f xs (x:ys)
%o | otherwise = f xs ys
%o isSquMod u v = u `mod` v `elem` (map ((`mod` v) . (^ 2)) [0..v-1])
%o -- _Reinhard Zumkeller_, fixed Jul 29 2015, Mar 28 2012
%Y Cf. A034698.
%Y Cf. A034793, A034903.
%K nonn
%O 1,2
%A _David W. Wilson_