• + 1 comment

    C++ Solution and Explaination:

    At first I had tried to modulos N by 10 (n = n%10) and set the number of if statements for each possibility from 1 to 10 to determine the winner, I was completely wrong. So I purchased the Test Cases for TC #0 and noticed that the pattern repeated itself after the 7th entry, it would go "Second First First First First First Second" and after that the pattern was the same. So I realized the best answer was to check if n was equal or greater than 7 and if so modulus n by 7 (n = n % 7). If the remainder was 0, it meant n was equal to the 7th case of the pattern (7 or 14 for example) and Player 2 Wins or if the reminder was 1, it meant n was equal to the 1st case of the pattern (8 or 15 for example) and Player 2 wins, any other remainder meant Player 1 wins.

    int main() {
        int t;
        cin >> t;
        
        for(int i = 0; i < t; i++){
            int n;
            cin >> n;
            
            if(n >= 7)
                n %= 7;
            
            if(n == 0 || n == 1)
                cout << "Second" <<  endl;
            else
                cout << "First" << endl;
            
        }
        return 0;
    }