# Why WA in DCP-241: Logic-Man

Dev Skill archived problems can be discussed here.

### Why WA in DCP-241: Logic-Man

I am trying to solve DCP-241: Logic-Man problem . My code is as following :
Code: Select all
`#include<stdio.h>#include<string.h>#include<math.h>#include<ctype.h>#include<memory.h>#include<iostream>#include<string>#include<algorithm>#include<utility>#include<iterator>#include<stack>#include<queue>#include<vector>#include<map>#include<set>using namespace std;#define ll long long#define pi 2*acos(0.0)#define inf 1<<30#define mod 1000000007int a[100010];int main(){    int t,c=1;    cin >> t;    while(t--) {        int n;        cin >> n;        int sum = 0;        for(int i=0; i<n; i++) {            cin >> a[i];        }        for (int i = 0; i < 32; i++)        {            int k = 0;            for (int j = 0; j < n; j++)                if ( !(a[j] & (1 << i)) )                    k++;            sum += (1<<i) * (n*(n-1)/2 - k*(k-1)/2);        }        cout << "Case " << c << ": " << sum << endl;        c++;    }return 0;}`

Where is the error in my code ?
And a test case will be very helpful.

Posts: 2
Joined: Sun Jun 18, 2017 8:49 pm

### Re: Why WA in DCP-241: Logic-Man

Answer will exceeds integer. So, try to change datatype used for "sum" variable.

Posts: 43
Joined: Tue Jan 17, 2017 10:10 pm

### Re: Why WA in DCP-241: Logic-Man

Thanks

Posts: 2
Joined: Sun Jun 18, 2017 8:49 pm

Who is online
Users browsing this forum: No registered users and 1 guest