Cerinta completa

Given an integer , find each such that:

where denotes the bitwise XOR operator. Return the number of ‘s satisfying the criteria.

Example

There are four values that meet the criteria:

Return .

Function Description

Complete the sumXor function in the editor below.

sumXor has the following parameter(s):
int n: an integer

Returns
int: the number of values found

Input Format

A single integer, .

Constraints

Subtasks

  • for of the maximum score.

Output Format

Sample Input 0

5

Sample Output 0

2

Explanation 0

For , the values and satisfy the conditions:

Sample Input 1

10

Sample Output 1

4

Explanation 1

For , the values , , , and satisfy the conditions:


Limbajul de programare folosit: java8

Cod:

import java.util.Scanner;

public class Solution {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long n = sc.nextLong();
		System.out.println(solve(n));

		sc.close();
	}

	static long solve(long n) {
		if (n == 0) {
			return 1;
		}

		return 1L << Long.toBinaryString(n).chars().filter(ch -> ch == '0').count();
	}
}

Scor obtinut: 1.0

Submission ID: 464603515

Link challenge: https://www.hackerrank.com/challenges/sum-vs-xor/problem

Sum vs XOR