fork download
  1. import java.io.*;
  2. import java.util.*;
  3. class Ideone {
  4. static class Fast{
  5. Fast() throws IOException{
  6. st=new StringTokenizer(br.readLine());
  7.  
  8. }
  9. String next() throws IOException {
  10. if(st.hasMoreTokens()){
  11. return st.nextToken();
  12. }
  13. else{
  14. st=new StringTokenizer(br.readLine());
  15. return st.nextToken();
  16. }
  17.  
  18. }
  19. String nextLine() throws IOException{
  20. String str;
  21. if(st.hasMoreTokens()){
  22. str = st.nextToken("\n");
  23. }
  24. else{
  25. str = br.readLine();
  26. }
  27. return str;
  28. }
  29. int nextInt() throws IOException{
  30. return Integer.parseInt(next());
  31. }
  32. long nextLong() throws IOException{
  33. return Long.parseLong(next());
  34. }
  35. double nextDouble() throws IOException{
  36. return Double.parseDouble(next());
  37. }
  38. void print(Object o) throws IOException{
  39. String s=String.valueOf(o);
  40. bw.write(s);
  41. bw.flush();
  42. }
  43. void println(Object o) throws IOException{
  44. String s=String.valueOf(o);
  45. bw.write(s+"\n");
  46. bw.flush();
  47. }
  48. }
  49.  
  50. public static void main(String args[]) throws IOException {
  51. Fast f=new Fast();
  52. int t=f.nextInt();
  53. while(t--!=0){
  54. int n=f.nextInt();
  55. int arr[]=new int[n];
  56. for(int i=0;i<n;i++){
  57. arr[i]=f.nextInt();
  58. }
  59. int res=0;
  60. for(int i=0;i<32;i++){
  61. int havingset=0;
  62. int temp=0;
  63. int havingunset=0;
  64. for(int j=0;j<arr.length;j++){
  65. if((arr[j]&1)==1){
  66. havingset++;
  67. }
  68. else{
  69. havingunset++;
  70. }
  71. arr[j]=arr[j]>>1;
  72. }
  73. temp=havingset*havingunset*(1<<i);
  74. res+=temp;
  75. }
  76. System.out.println(2*res);
  77. }
  78. }
  79. }
Success #stdin #stdout 0.08s 47368KB
stdin
3
3
5 12 8 
5
4 10 54 11 8 
6
15 35 25 10 15 12 
stdout
52
560
680