Nobody's going to be able to figure out how to get 40. Sorry. This type problem is unfair, because there are millions of possible patterns. There is no rule for getting the pattern. This site https://oeis.org/ has thousands and thousands of integer sequences with patterns. There is no end to them, and no general way to figure out patterns. Who gave you such an unfair problem? Edwin