Cerinta completa

After their success in coming up with Fun Game, Kyle and Mike invented another game having the following rules:

  • The game starts with an -element sequence, , and is played by two players, and .
  • The players move in alternating turns, with always moving first. During each move, the current player chooses one of the asterisks () in the above sequence and changes it to either a + (plus) or a - (minus) sign.
  • The game ends when there are no more asterisks () in the expression. If the evaluated value of the sequence is divisible by , then wins; otherwise, wins.

Given the value of , can you determine the outcome of the game? Print if will win, or if will win. Assume both players always move optimally.

Input Format

The first line of input contains a single integer , denoting the number of test cases.
Each line of the subsequent lines contains an integer, , denoting the maximum exponent in the game’s initial sequence.

Constraints

Output Format

For each test case, print either of the following predicted outcomes of the game on a new line:

  • Print if will win.
  • Print if will win.

Sample Input

1
2  

Sample Output

First

Explanation

In this case, it doesn’t matter in which order the asterisks are chosen and altered. There are different courses of action and, in each one, the final value is not divisible by (so always loses and we print on a new line).

Possible options:


Limbajul de programare folosit: java8

Cod:

import java.io.*;

public class Solution {
    private static class FastScanner {
        private final InputStream in;
        private final byte[] buffer = new byte[1 << 16];
        private int ptr = 0, len = 0;

        FastScanner(InputStream is) {
            this.in = is;
        }

        private int read() throws IOException {
            if (ptr >= len) {
                len = in.read(buffer);
                ptr = 0;
                if (len <= 0) return -1;
            }
            return buffer[ptr++];
        }

        int nextInt() throws IOException {
            int c;
            do {
                c = read();
            } while (c <= ' ' && c != -1);

            int sign = 1;
            if (c == '-') {
                sign = -1;
                c = read();
            }

            int val = 0;
            while (c > ' ') {
                val = val * 10 + (c - '0');
                c = read();
            }
            return val * sign;
        }
    }

    public static void main(String[] args) throws Exception {
        FastScanner fs = new FastScanner(System.in);
        int t = fs.nextInt();
        StringBuilder out = new StringBuilder(t * 7);

        for (int i = 0; i < t; i++) {
            int n = fs.nextInt();
            out.append((n % 8 == 0) ? "Second" : "First").append('\n');
        }

        String outputPath = System.getenv("OUTPUT_PATH");
        if (outputPath != null && !outputPath.isEmpty()) {
            try (BufferedWriter bw = new BufferedWriter(new FileWriter(outputPath))) {
                bw.write(out.toString());
            }
        } else {
            System.out.print(out);
        }
    }
}

Scor obtinut: 1.0

Submission ID: 464614111

Link challenge: https://www.hackerrank.com/challenges/powers-game-1/problem

Powers Game