Python 3.3 NZEC (Pairwise AND Sum)

import math
import sys

n = 1
cases = 0
num = 0
arr = [0 for i in range(0,30)]
ans = 0


#print('Enter the test cases')
cases = int(input())

while cases:
    num = int(input())

    for i in range(0,30):

        if num % 2 == 1:
            arr[i] = arr[i] + 1
        num  = num // 2

        if num == 0:
            break
    cases-=1

#print('Arr: ',arr)
for i in range(0,30):
    if arr[i]:
        ans = ans + (n * arr[i] * (arr[i] - 1))//2
        n = n*2

print(int(ans))

Can some one tell me why am i getting NZEC… This runs fine in idle

the error is in the way u r taking input…the “n” numbers are space-separated integers…u need to take string as input ans split them and then convert to int…hope this helps…:slight_smile:

this is ur corrected code…LINK!!!

@ash4code plz give link for the question

thank you kunal361…it works…Btw just curious on how the input format is related to a non-zero error code run time error??

arr[i] = arr[i] + 1
num = num // 2

    if num == 0:
        break
cases-=1 

after change

num = num+1;

t=raw_input();
t=int(t);
arr=[2,3,5];
ans =[];
for v in range (0,t):
n = raw_input();
n = int(n);
if(n<=len(arr)):
ans = ans + [arr[n-1]];
else:
prime(arr,n);print arr;print"arr was printed"
ans= ans + [arr[n-1]];

mostly it is because ur code returned a number format exception…or something similar…!!!