Given an integer N, the task is to find the ways to choose some balls out of the given N balls such that at least one ball is chosen. Since the value can be large so print the value modulo 1000000007. Example:
Input: N = 2 Output: 3 The three ways are “*.”, “.*” and “**” where ‘*’ denotes the chosen ball and ‘.’ denotes the ball which didn’t get chosen. Input: N = 30000 Output: 165890098
Approach: There are N balls and each ball can either be chosen or not chosen. Total number of different configurations is 2 * 2 * 2 * … * N. We can write this as 2N. But the state where no ball is chosen has to be subtracted from the answer. So, the result will be (2N – 1) % 1000000007. Below is the implementation of the above approach:
Please Login to comment...