NoXor (Simple Contest)
Problem Statement
We need a problem on xor again. Given an array A of N integers (1- indexed), you need to find the sum of (N- i) xor A[i] for all i from 1 to N
import java.io.*;
import java.util.*;
class Main
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
if(N>0)
{
int A[]=new int[N];
for(int i=0;i<N;i++)
{
A[i]=sc.nextInt();
}
long sum=0;
for(int i=1;i<=N;i++)
{
int P=(N-i)^A[(i-1)];
sum=sum+P;
}
System.out.println(sum);
}
}
}