Wednesday, 19 July 2017

Sum vs Array

Given an integer, , find each such that:


where denotes the bitwise XOR operator. Then print an integer denoting the total number of 's satisfying the criteria above.
Input Format
A single integer, .
Constraints

Subtasks
  • for of the maximum score.
Output Format
Print the total number of integer 's satisfying both of the conditions specified above.
Sample Input 0
5
Sample Output 0
2
Explanation 0
For , the values and satisfy the conditions:


Thus, we print as our answer.
Sample Input 1
10
Sample Output 1
4
Explanation 1
For , the values , , , and satisfy the conditions:




Thus, we print as our answer.


#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

long int solve(long int n) {
    // Complete this function)
    long count =0;
    while (n>0)
    {
        if (n%2==0)
        { count++;}
        n=n>>1;
        
    }
    //printf("%d",count) ;
    unsigned long int q=1;
    return (q<<count);
}

int main() {
    long int n;
    scanf("%li", &n);
    long int result = solve(n);
    printf("%ld\n", result);
    return 0;
}

No comments:

Post a Comment