-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEscapeNight.java
More file actions
31 lines (29 loc) · 803 Bytes
/
EscapeNight.java
File metadata and controls
31 lines (29 loc) · 803 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
/**
* https://www.hackerearth.com/practice/basic-programming/bit-manipulation/basics-of-bit-manipulation/practice-problems/algorithm/escape-the-night/
* #bit-manipulation
*/
import java.util.Scanner;
class EscapeNight {
static final int MAX = (int) 1e9 + 7;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int testcases = sc.nextInt();
for (int t = 0; t < testcases; t++) {
long n = sc.nextLong();
long sum = 0, val = 0, v = 1;
// 64bit
for (int i = 1; i < 63; i++) {
for (int j = 0; j < i; j++) {
val = (v << i) | (v << j);
if (val <= n) {
sum += val;
sum %= MAX;
} else {
break;
}
}
}
System.out.println(sum);
}
}
}