A multistep reciprocity gap functional method for the inverse problem in a multilayered medium