login
Smallest nonnegative integer such that n + (a(n))^2 is a perfect square, or -1 if no such integer exists.
2

%I #6 Jan 21 2019 20:03:45

%S 0,-1,1,0,2,-1,3,1,0,-1,5,2,6,-1,1,0,8,-1,9,4,2,-1,11,1,0,-1,3,6,14,

%T -1,15,2,4,-1,1,0,18,-1,5,3,20,-1,21,10,2,-1,23,1,0,-1,7,12,26,-1,3,5,

%U 8,-1,29,2,30,-1,1,0,4,-1,33,16,10,-1,35,3,36,-1,5,18,2,-1,39,1,0,-1,41,4,6

%N Smallest nonnegative integer such that n + (a(n))^2 is a perfect square, or -1 if no such integer exists.

%C a(n) = -1 for all n == 2 (mod 4).

%e a(7) = 3 because 7 + 1 = 8 and 7 + 4 = 11 are not perfect squares, but 7 + 9 = 16 is.

%p A172038 := proc(n) local r,kpa,kma,a,k ; r := {} ; for kpa in numtheory[divisors](n) do kma := n/kpa ; if type(kpa-kma,'even') then a := (kpa-kma)/2 ; k := kpa- a; if a >= 0 and k >= 0 and kpa+kma = 2*k then r := r union {a}; end if; end if; end do ; if r <> {} then return min(op(r)) ; else return -1 ; end if; end proc: for n from 1 to 100 do printf("%d,",A172038(n)) ; end do : # _R. J. Mathar_, Feb 07 2010

%K sign

%O 1,5

%A _J. Lowell_, Jan 23 2010

%E More terms from _R. J. Mathar_, Feb 07 2010