If you're into sci-fi short stories, Isaac Asimov's "The Last Question" [1] is more or less
the story about this, although it's heavier on the twist ending aspect and lighter on the solving-the-problem-in-reality aspect.
[1] https://www.multivax.com/last_question.html