Count number of disjoint subsets
Submissions: 120   Accuracy:

14.16%

  Difficulty: Easy   Marks: 2

Consider the set A = {1,2,3,…,N}. Let M and P be two non-empty subsets of  A.  The task is to count the number of unordered pairs of (M, P) such that M and P are disjoint sets. Note that the order of M and P doesn’t matter. For example, if N = 3 and M = {1} and P = {2,3}, then this is the same as M = {3,2} and P = {1}. The answer must be given modulo 109 + 7.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. 
The first and only line of each test case contains an integer N, where N is the size of the set A.

Output:
For each test case in a new line, print the number of such unordered pairs modulo 109 + 7.

Constraints:
1 <= T <= 200
1 <= N <= 1018

 

Example:

Input:
4
2
3
10
5

Output:
1
6
28501 
90

Explanation:

Consider N = 3, the unordered pairs are ({1}, {2}), ({1}, {3}), ({2}, {3}), ({1}, {2,3}), ({2}, {1,3}), ({3}, {1,2}).


 

Expected Complexity:

O(logN)

 

** For More Input/Output Examples Use 'Expected Output' option **

Author: Hemang Sarkar


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.