Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CountOfEqualBitPairs {
- static int count = 0;
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- int number = input.nextInt();
- for (int i = 31; i > 0; i--) {
- int temp = 1 << i & number;
- if (temp == 0) {
- continue;
- } else {
- for (int j = i; j >= 0; j--){
- int t = (3 << j) & number;
- int t1 = number>>j & 1;
- int t2 = number>>j-1 &1;
- if (t >> j == 3) {
- count++;
- }else if(t1 == 0 && t2 == 0){
- count++;
- }
- }
- break;
- }
- }
- input.close();
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment