A reconstruction theorem in quantum cohomology and quantum K-theory