This problem asks:

Given: A positive integer n (n≤1000).

Return: The total number of subsets of {1,2,…,n} modulo 1,000,000.

Required reading

  1. Number of subsets in a set
  2. Modulo

Restate the problem

I’m going to get a positive integer, n, less than 1000. I need to return the number of subsets of counting numbers up to and including n.

Solution steps

Since the number of subsets for any set with n elements is 2**n, the solution to this challenge is:

print((2**n)%1000000)

where n is the integer received from Project Rosalind.

** is the Python operator for exponentiation, so 2*_n_ in Python means 2 to the *nth power.

My full code is:

if __name__ == "__main__":
    file_path = "/Users/robertbryan/Downloads/rosalind_sset.txt"
    file = open(file_path, "r").readline()
    n = int(file)
    print((2**n)%1000000)

Because 2**n becomes awkwardly large for modest values of n, we return our response modulo 1,000,000 to prove that we have calculated the answer correctly without having to transmit excessively large values.

For example, the n I received from Project Rosalind for my challenge dataset was 935. My response modulo 1,000,000 was 690368, which is relatively easy to deal with.

The full value of 2**935 has 282 decimal digits. For comparison, I’ve included it below as an appendix.

My first response was correct. This challenge took about 15 minutes. 2,989 people solved this before me. I was the second person to solve this on August 10, 2025. Almost all solvers used 2**n to calculate the answer to this challenge. A few others tried generating all the possible subsets, then counting them. That approach leads to timing struggles because it is so inefficient.

Appendix: Decimal value of 2**935

290432989937067004452746581669902453150636758136600480284330441272644659601641479208040686425030537224570063240272065048916911180770489396052896597871561450348236492274894506629430939420761276732468592926240515079310107169312085954718183386786847281838290059659012482973391669690368