Skip to content

Instantly share code, notes, and snippets.

@feynmanliang
Created February 22, 2012 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save feynmanliang/1888417 to your computer and use it in GitHub Desktop.
Save feynmanliang/1888417 to your computer and use it in GitHub Desktop.
Solution to 2s complement csfall11
/*
Please write complete compilable code.
Your class should be named Solution
Read input from standard input (STDIN) and print output to standard output(STDOUT).
For more details, please check http://www.interviewstreet.com/recruit/challenges/faq/view#stdio
*/
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int numCases = scan.nextInt();
int[] output = new int[numCases];
for (int i = 0; i < numCases; ++i) {
int solution = 0;
int a = scan.nextInt(), b = scan.nextInt();
for (int j = a; j <= b; ++j) {
int bits = Integer.bitCount(j);
solution += bits;
}
output[i] = solution;
}
for (int line=0; line < numCases; ++line)
System.out.println(output[line]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment