For n this to be divisible by 40 we need to show that it is divisible by 8 and 5 as 40 = 8 * 5 and 8 and 5 are co-primes
First let us prove that 8 divides n
Clearly 2n+1 is odd so this has to be square of odd number say 2k+1
Now (2k+1)^2 = 4k^2 + 4k +1=4k(k+1)+1 = 4m+1 when m= k(k+1)
or 2n+1 = 8m+1 or n= 4m
so n is even and hence 3n+1 is odd so square of odd number say 2p+1
3n+1 = (2p+1)^2 = 4p^2 + 4p +1 = 4p(p+1) +1
or 3n = 4p(p+1) as p(p+1) is even it can be written as 2q
as 3n+1 = 8q+15
or 3n = 8q
So 8 divides 3n and as 8 and 3 are copimes so 8 divides n
now let us prove that 5 divides n
let us find what are the numbers that can be remainder of x^2 when divided by 5
we have x of the form 5q+k where k is one of 0,\pm 1,\pm 2
x^2= 25q^2 + 10kq +k^2
= 5(5q^2 + 2k) + k^2
so remainder when x^2 divided by by5 is 0 or 1 or 4
now let us find n for which 2n+1 give a remainder 0 or 1 or 4 else it cannot be a square.
n = 5k gives 2n + 1 = 10 k + 1 = 5 * 2k + 1 remainder is 1 which is a valid candidate
n = 5k+ 1 gives 2n + 1 = 10 k +3 = 5 * 2k +3 remainder is 3 which is a not a valid candidate
n = 5k+ 2 gives 2n + 1 = 10 k +5 = 5 * (2k +1) remainder is 0 which is a valid candidate
n = 5k+ 3 gives 2n + 1 = 10 k +7 = 5 * (2k +1)+2 $ remainder is 2 which is a not a valid candidate
n = 5k+ 4 gives 2n + 1 = 10 k +9 = 5 * (2k +1)+ 4 remainder is 4 which is a valid candidate
So valid candidates for 2n+1 being perfect square is 5k, 5k+2, 5k+ 4
and we need to check for these one 3n+1 is valid
we can apply above procedure to see the n= 5k 3n+1 leaves remainder 1 which is valid and for n=5k+2 remainder is 2 and for n=5k+4 remainder is 3 both of which are invalid
so n is multiple of 5.
as n is divisible by 5 and 8 so by 40