Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.math.BigInteger;
- import java.util.*;
- public class Main {
- static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
- private final static Random rnd = new Random();
- class DSU {
- int parents[];
- int size;
- DSU(int size) {
- this.size = size;
- this.parents = new int[size];
- for (int i = 0; i < size; i++) {
- parents[i] = i;
- }
- }
- int get(int v) {
- int parent = parents[v];
- if (parent == v)
- return v;
- return parents[v] = get(parent);
- }
- void union(int a, int b) {
- a = get(a);
- b = get(b);
- if (a != b) {
- size--;
- if (rnd.nextBoolean()) {
- parents[a] = b;
- } else {
- parents[b] = a;
- }
- }
- }
- }
- public static void main(String[] args) {
- new Main().run();
- }
- BufferedReader in;
- PrintWriter out;
- StringTokenizer tok;
- int maxA(int[] a) {
- int max = Integer.MIN_VALUE;
- for (int i = 0; i < a.length; i++) {
- if (a[i] > max) {
- max = a[i];
- }
- }
- return max;
- }
- int minA(int[] a) {
- int min = Integer.MAX_VALUE;
- for (int i = 0; i < a.length; i++) {
- if (a[i] < min) {
- min = a[i];
- }
- }
- return min;
- }
- void init() throws FileNotFoundException {
- if (ONLINE_JUDGE) {
- in = new BufferedReader(new InputStreamReader(System.in));
- out = new PrintWriter(System.out);
- } else {
- in = new BufferedReader(new FileReader("input.txt"));
- out = new PrintWriter("output.txt");
- }
- tok = new StringTokenizer("");
- }
- void run() {
- try {
- long timeStart = System.currentTimeMillis();
- init();
- solve();
- out.close();
- long timeEnd = System.currentTimeMillis();
- System.err.println("Time = " + (timeEnd - timeStart) + " COMPILED");
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(-1);
- }
- }
- long memoryTotal, memoryFree;
- void memory() {
- memoryFree = Runtime.getRuntime().freeMemory();
- System.err.println("Memory = " + ((-memoryTotal + memoryFree) >> 10) + " KB");
- }
- String readLine() throws IOException {
- return in.readLine();
- }
- String delimiter = " ";
- String rS() throws IOException {
- while (!tok.hasMoreTokens()) {
- String nextLine = readLine();
- if (null == nextLine)
- return null;
- tok = new StringTokenizer(nextLine);
- }
- return tok.nextToken(delimiter);
- }
- int[] rA(int b) {
- int a[] = new int[b];
- for (int i = 0; i < b; i++) {
- try {
- a[i] = rI();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return a;
- }
- int rI() throws IOException {
- return Integer.parseInt(rS());
- }
- long rL() throws IOException {
- return Long.parseLong(rS());
- }
- void sort(int[] a) {
- Integer arr[] = new Integer[a.length];
- for (int i = 0; i < a.length; i++) {
- arr[i] = a[i];
- }
- Arrays.sort(arr);
- for (int i = 0; i < a.length; i++) {
- a[i] = arr[i];
- }
- }
- // void initGraph(int a) {
- // for (int i = 0; i < a; i++) {
- // graph[i] = new ArrayList<Integer>();
- // }
- // }
- //
- // List<Integer> graph[];
- long can(long x) {
- return x * (x + 1) / 2;
- }
- void solve() throws IOException {
- int n = rI();
- outer: while (n-- > 0) {
- long summ = rL();
- if (summ == 1 || summ == 2 || summ == 4 || summ == 7 || summ == 11 || summ == 16 || summ == 22 ) {
- out.print(1 + " ");
- continue;
- }
- long ans = (long) (1 + Math.sqrt(1 + 2 * summ));
- if (summ < 23) {
- out.print(0 + " ");
- continue outer;
- }
- for (int i = -5; i <= Math.sqrt(ans); i++) {
- if (can(ans + i) + 1 == summ) {
- out.print(1 + " ");
- continue outer;
- }
- }
- out.print(0 + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement