The number of subsets of a set of size is . The following code implements the repeated squaring algorithm. The numbers are computed modulo as soon as we are done with multiplying. This is done to keep the number small, and so that the multiplications are quick.