How can you write an equation to represent this problem for any number of guards?

A man entered an orchard through 7 gates and picked some apples. When he left, he gave the first guard half his apples and 1 apple more. To the second guard he gave half his remaining apples and 1 more. He did the same to each of the remaining five guards and left the orchard with 1 apple. How many apples did he gather in all?