Graph cycles on 40 vertices
When you say "cycle", do you mean a simple cycle of length 40 (so no vertex is allowed to be repeated), or would you allow an arbitrary walk of length 40 that ends where it starts (i.e., vertices are allowed to be repeated in the cycle)?  The answer to your question depends on what you mean by cycle, so I'll answer both cases.

Simple cycles

The problem of testing whether a graph contains a simple cycle of length $k$ is hard.

No efficient algorithm is known; all known algorithms have running time that is exponential in $k$; and if $k$ is part of the input, the problem is NP-hard.  See here and here.  In your case, $k=40$.  The best algorithms that I know of have either a $O(k!)$ factor or a $O(n^{k/2})$ factor in the running time, so they will be totally infeasible: $O(n^{20})$ is not feasible for any non-trivial value of $n$, and $k! \approx 2^{159} \approx 10^{48}$, which is also infeasibly large.  (See Louis's answer for pointers to an algorithm of the former type.)

If you allow repeated vertices

If you allow the cycle to contain repeated vertices, then the problem becomes much easier, and there is a polynomial-time solution.

Hint: Consider the adjacency matrix of the graph, $M$.  Look at $M^2$.  Can you find any relationship between the $i,j$ entry of $M^2$ and paths of some length?  Can you generalize?

(Since this looks like a natural exercise problem, I am just giving you a hint, and letting you take it from here.)