I am having problem with finding sum of i|j given 0<i,j<n over="" all="" i,j=""

时间:2019-06-01 14:13:00

标签: bit-manipulation bitwise-or

="" Given only n, we have to find sum(i|j) over all i,j in range.(0,n)

i have tried to split it into ranges of power of 2 but not getting proper insight of how to solve

i used O(n^2) code:

int s=0;
     for(int i=1;i<=n;i++)
     {for(int j=1;j<=n;j++)s+=(i|j);}

i get expected output but i need optimum solution.

0 个答案:

没有答案