-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMCHAIRS.java
More file actions
64 lines (40 loc) · 963 Bytes
/
MCHAIRS.java
File metadata and controls
64 lines (40 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class Ideone{
//https://www.codechef.com/problems/MCHAIRS
public static Scanner scn = new Scanner(System.in);
public static int MOD = 1000000007;
public static void main (String[] args) throws java.lang.Exception{
int T = scn.nextInt();
while(T-- > 0){
int N = scn.nextInt();
long ans = getAns(2,N) - 1;
System.out.println(ans);
}
}
public static long getAns(int x, int n){
if(n == 0)
return 1;
if(n == 1)
return x;
long res = getAns(x, n/2);
res = (res % MOD * res % MOD)%MOD;
if(n % 2 == 1)
res = (res % MOD * x % MOD)%MOD;
return res;
}
public static long getAns2(int x, int n){
long r = 1;
long y = x;
while (n > 1) {
if (n%2 == 1)
r = (r*y)%MOD;
n = (int)Math.floor(n/2);
y = (y*y)%MOD;
}
r = (r*y)%MOD;
return r;
}
}