I got this question yesterday in a challenge. I thought I had coded it correctly and my sample test case was passed. However not even a single test case passed at the backend. Here is my code. Please, someone, help me out. The challenge is over for me and so I can't submit it further. But I want to learn from my mistakes. Thanks.
import java.io.*;
//import java.util.*;
public class TestClass {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter wr = new PrintWriter(System.out);
int n = Integer.parseInt(br.readLine().trim());
String[] arr_a = br.readLine().split(" ");
int[] a = new int[n];
for(int i_a=0; i_a<arr_a.length; i_a++)
{
a[i_a] = Integer.parseInt(arr_a[i_a]);
}
long out_ = solve(a);
System.out.println(out_);
wr.close();
br.close();
}
static long solve(int[] a){
// Write your code here
long sum = 0l;
long MAX = 10000000011l;
long i = 1l;
for(int x : a) {
long count = 0;
while(x>0) {
x &= (x-1l);
count++;
}
long res = 1l;
long temp = i;
count = count % MAX;
while(temp > 0) {
if((temp & 1l) == 1l) {
res = (res * count) % MAX;
}
temp = temp >> 1l;
count = ((count % MAX) * (count % MAX)) % MAX;
}
long t =((sum%MAX) + (res % MAX))%MAX;
sum = t;
i++;
}
return sum;
}
}