Skip to content

Commit a8ff8a8

Browse files
committed
package modified
1 parent c729220 commit a8ff8a8

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/com/hackerrank/bitmanipulation/CounterGame.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.ramswaroop.bitmanipulation;
1+
package com.hackerrank.bitmanipulation;
22

33
import java.math.BigInteger;
44
import java.util.Scanner;

src/com/hackerrank/bitmanipulation/Solution.java

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.ramswaroop.bitmanipulation;
1+
package com.hackerrank.bitmanipulation;
22

33
import java.io.BufferedReader;
44
import java.io.IOException;
@@ -14,42 +14,46 @@
1414
public class Solution {
1515
private final static byte BITS;
1616
private final static long[] BIT_COUNT_TO_BIT;
17+
1718
static {
1819
BITS = 32;
19-
BIT_COUNT_TO_BIT = new long[BITS+1];
20+
BIT_COUNT_TO_BIT = new long[BITS + 1];
2021
BIT_COUNT_TO_BIT[0] = 1;
21-
for(byte i = 1; i <= BITS; i++){
22-
BIT_COUNT_TO_BIT[i] = ((BIT_COUNT_TO_BIT[i-1] - 1L) << 1) + (1L << (i-1)) + 1L;
22+
for (byte i = 1; i <= BITS; i++) {
23+
BIT_COUNT_TO_BIT[i] = ((BIT_COUNT_TO_BIT[i - 1] - 1L) << 1) + (1L << (i - 1)) + 1L;
2324
}
2425
}
26+
2527
public static void main(String[] args) throws IOException {
2628
StringBuffer sb = new StringBuffer();
2729
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
28-
for(short T = Short.parseShort(br.readLine()); T > 0; T--){
30+
for (short T = Short.parseShort(br.readLine()); T > 0; T--) {
2931
String[] temp = br.readLine().split(" ");
3032
int A = Integer.parseInt(temp[0]);
3133
int B = Integer.parseInt(temp[1]);
3234
long bits = bitCountToNum(B) - bitCountToNum(A) + getHammingWeight(A);
33-
bits += (A < 0 && B >= 0) ? BIT_COUNT_TO_BIT[BITS] - 1L: 0;
35+
bits += (A < 0 && B >= 0) ? BIT_COUNT_TO_BIT[BITS] - 1L : 0;
3436
sb.append(bits + "\n");
3537
}
3638
System.out.print(sb);
3739
}
40+
3841
//Bit count in number
39-
private static int getHammingWeight(int n){
42+
private static int getHammingWeight(int n) {
4043
byte count = 0;
41-
while(n != 0){
44+
while (n != 0) {
4245
count++;
43-
n &= n-1;
46+
n &= n - 1;
4447
}
4548
return count;
4649
}
50+
4751
//Bit count to number, inclusive
48-
private static long bitCountToNum(int n){
52+
private static long bitCountToNum(int n) {
4953
long count = 0;
50-
for(byte b = BITS; n != 0;){
54+
for (byte b = BITS; n != 0; ) {
5155
int x = 1 << --b;
52-
if((n & x) != 0){
56+
if ((n & x) != 0) {
5357
n &= ~x;
5458
count += BIT_COUNT_TO_BIT[b] + n;
5559
}

src/com/hackerrank/bitmanipulation/TwosCompliment.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package me.ramswaroop.bitmanipulation;
1+
package com.hackerrank.bitmanipulation;
22

33
import java.util.Scanner;
44

0 commit comments

Comments
 (0)