Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. import java.io.*;
  2. import java.math.BigInteger;
  3. import java.util.*;
  4.  
  5. public class Main {
  6.  
  7. static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
  8. private final static Random rnd = new Random();
  9.  
  10. class DSU {
  11.  
  12. int parents[];
  13. int size;
  14.  
  15. DSU(int size) {
  16. this.size = size;
  17. this.parents = new int[size];
  18. for (int i = 0; i < size; i++) {
  19. parents[i] = i;
  20. }
  21. }
  22.  
  23. int get(int v) {
  24. int parent = parents[v];
  25. if (parent == v)
  26. return v;
  27. return parents[v] = get(parent);
  28. }
  29.  
  30. void union(int a, int b) {
  31. a = get(a);
  32. b = get(b);
  33. if (a != b) {
  34. size--;
  35. if (rnd.nextBoolean()) {
  36. parents[a] = b;
  37. } else {
  38. parents[b] = a;
  39. }
  40.  
  41. }
  42. }
  43.  
  44. }
  45.  
  46. public static void main(String[] args) {
  47. new Main().run();
  48. }
  49.  
  50. BufferedReader in;
  51. PrintWriter out;
  52. StringTokenizer tok;
  53.  
  54. int maxA(int[] a) {
  55. int max = Integer.MIN_VALUE;
  56. for (int i = 0; i < a.length; i++) {
  57. if (a[i] > max) {
  58. max = a[i];
  59.  
  60. }
  61. }
  62. return max;
  63. }
  64.  
  65. int minA(int[] a) {
  66. int min = Integer.MAX_VALUE;
  67. for (int i = 0; i < a.length; i++) {
  68. if (a[i] < min) {
  69. min = a[i];
  70.  
  71. }
  72. }
  73. return min;
  74. }
  75.  
  76. void init() throws FileNotFoundException {
  77.  
  78. if (ONLINE_JUDGE) {
  79. in = new BufferedReader(new InputStreamReader(System.in));
  80. out = new PrintWriter(System.out);
  81. } else {
  82. in = new BufferedReader(new FileReader("input.txt"));
  83. out = new PrintWriter("output.txt");
  84. }
  85.  
  86. tok = new StringTokenizer("");
  87. }
  88.  
  89. void run() {
  90. try {
  91. long timeStart = System.currentTimeMillis();
  92.  
  93. init();
  94. solve();
  95.  
  96. out.close();
  97.  
  98. long timeEnd = System.currentTimeMillis();
  99. System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
  100. } catch (Exception e) {
  101. e.printStackTrace();
  102. System.exit(-1);
  103. }
  104. }
  105.  
  106. long memoryTotal, memoryFree;
  107.  
  108. void memory() {
  109. memoryFree = Runtime.getRuntime().freeMemory();
  110. System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
  111. }
  112.  
  113. String readLine() throws IOException {
  114. return in.readLine();
  115. }
  116.  
  117. String delimiter = " ";
  118.  
  119. String rS() throws IOException {
  120. while (!tok.hasMoreTokens()) {
  121. String nextLine = readLine();
  122. if (null == nextLine)
  123. return null;
  124.  
  125. tok = new StringTokenizer(nextLine);
  126. }
  127.  
  128. return tok.nextToken(delimiter);
  129. }
  130.  
  131. int[] rA(int b) {
  132. int a[] = new int[b];
  133. for (int i = 0; i < b; i++) {
  134. try {
  135. a[i] = rI();
  136. } catch (IOException e) {
  137. e.printStackTrace();
  138. }
  139. }
  140. return a;
  141. }
  142.  
  143. int rI() throws IOException {
  144. return Integer.parseInt(rS());
  145. }
  146.  
  147. long rL() throws IOException {
  148. return Long.parseLong(rS());
  149. }
  150.  
  151. void sort(int[] a) {
  152. Integer arr[] = new Integer[a.length];
  153. for (int i = 0; i < a.length; i++) {
  154. arr[i] = a[i];
  155. }
  156. Arrays.sort(arr);
  157. for (int i = 0; i < a.length; i++) {
  158. a[i] = arr[i];
  159. }
  160. }
  161.  
  162. // void initGraph(int a) {
  163. // for (int i = 0; i < a; i++) {
  164. // graph[i] = new ArrayList<Integer>();
  165. // }
  166. // }
  167. //
  168. // List<Integer> graph[];
  169. long can(long x) {
  170. return x * (x + 1) / 2;
  171.  
  172. }
  173.  
  174. void solve() throws IOException {
  175. int n = rI();
  176. outer: while (n-- > 0) {
  177.  
  178. long summ = rL();
  179. if (summ == 1 || summ == 2 || summ == 4 || summ == 7 || summ == 11 || summ == 16 || summ == 22 ) {
  180. out.print(1 + " ");
  181. continue;
  182. }
  183.  
  184. long ans = (long) (1 + Math.sqrt(1 + 2 * summ));
  185. if (summ < 23) {
  186. out.print(0 + " ");
  187. continue outer;
  188. }
  189. for (int i = -5; i <= Math.sqrt(ans); i++) {
  190. if (can(ans + i) + 1 == summ) {
  191. out.print(1 + " ");
  192. continue outer;
  193. }
  194.  
  195. }
  196. out.print(0 + " ");
  197. }
  198. }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement