1. import java.io.*;
  2. import java.util.*;
  3. public class TestClass {
  4. static class Reader
  5. {
  6. final private int BUFFER_SIZE = 1 << 16;
  7. private DataInputStream din;
  8. private byte[] buffer;
  9. private int bufferPointer, bytesRead;
  10. public Reader()
  11. {
  12. din = new DataInputStream(System.in);
  13. buffer = new byte[BUFFER_SIZE];
  14. bufferPointer = bytesRead = 0;
  15. }
  16. public Reader(String file_name) throws IOException
  17. {
  18. din = new DataInputStream(new FileInputStream(file_name));
  19. buffer = new byte[BUFFER_SIZE];
  20. bufferPointer = bytesRead = 0;
  21. }
  22. public String readLine() throws IOException
  23. {
  24. byte[] buf = new byte[64]; // line length
  25. int cnt = 0, c;
  26. while ((c = read()) != -1)
  27. {
  28. if (c == '\n')
  29. break;
  30. buf[cnt++] = (byte) c;
  31. }
  32. return new String(buf, 0, cnt);
  33. }
  34. public int nextInt() throws IOException
  35. {
  36. int ret = 0;
  37. byte c = read();
  38. while (c <= ' ')
  39. c = read();
  40. boolean neg = (c == '-');
  41. if (neg)
  42. c = read();
  43. do
  44. {
  45. ret = ret * 10 + c - '0';
  46. } while ((c = read()) >= '0' && c <= '9');
  47. if (neg)
  48. return -ret;
  49. return ret;
  50. }
  51. public long nextLong() throws IOException
  52. {
  53. long ret = 0;
  54. byte c = read();
  55. while (c <= ' ')
  56. c = read();
  57. boolean neg = (c == '-');
  58. if (neg)
  59. c = read();
  60. do {
  61. ret = ret * 10 + c - '0';
  62. }
  63. while ((c = read()) >= '0' && c <= '9');
  64. if (neg)
  65. return -ret;
  66. return ret;
  67. }
  68. public double nextDouble() throws IOException
  69. {
  70. double ret = 0, div = 1;
  71. byte c = read();
  72. while (c <= ' ')
  73. c = read();
  74. boolean neg = (c == '-');
  75. if (neg)
  76. c = read();
  77. do {
  78. ret = ret * 10 + c - '0';
  79. }
  80. while ((c = read()) >= '0' && c <= '9');
  81. if (c == '.')
  82. {
  83. while ((c = read()) >= '0' && c <= '9')
  84. {
  85. ret += (c - '0') / (div *= 10);
  86. }
  87. }
  88. if (neg)
  89. return -ret;
  90. return ret;
  91. }
  92. private void fillBuffer() throws IOException
  93. {
  94. bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
  95. if (bytesRead == -1)
  96. buffer[0] = -1;
  97. }
  98. private byte read() throws IOException
  99. {
  100. if (bufferPointer == bytesRead)
  101. fillBuffer();
  102. return buffer[bufferPointer++];
  103. }
  104. public void close() throws IOException
  105. {
  106. if (din == null)
  107. return;
  108. din.close();
  109. }
  110. }
  111. public static void main(String[] args) throws IOException {
  112. Reader r = new Reader();
  113. int t = r.nextInt();
  114. StringBuilder sb = new StringBuilder("");
  115. long[] arr = new long[60];
  116. for (int i = 0; i < 60; i++) {
  117. arr[i] = (long) Math.pow(2, i);
  118. }
  119. while (t-- > 0) {
  120. int n = r.nextInt();
  121. long charge, sum = 0;
  122. if (n <= 60)
  123. charge = arr[n-1];
  124. else
  125. charge = 0;
  126. for (int i = 0; i < n; i++) {
  127. long number = r.nextLong();
  128. if (n <= 60 && number >= charge) {
  129. sum = (sum + (number % 1000000007)) % 1000000007;
  130. }
  131. }
  132. sb.append(sum+"\n");
  133. }
  134. System.out.println(sb);
  135. }
  136. }
Language: Java 8