Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerRank Powers Game problem solution

YASH PAL, 31 July 202426 January 2026

In this HackerRank Powers Game problem solution, we have given the value of the N element sequence and is played by two players P1 and P2. we need to determine the outcome of the game. Print First if P1 will win or Second if P2 will win. Assume both players always move optimally.

Input Format

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

HackerRank Powers Game problem solution

HackerRank Powers Game problem solution in Python.

T = int(input().strip())
for _ in range(T):
    n = int(input().strip())
    print('Second' if n % 8 == 0 else 'First')

Powers Game problem solution in Java.

import java.io.*;
import java.util.*;

public class Solution {

    public static void main(String[] args) {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        for(int a0=0; a0<t; a0++)
        {
            int n = in.nextInt();
            if(n % 8 == 0)
                System.out.print("Secondn");
            else
                System.out.print("Firstn");
        }
    }
}

Problem solution in C++.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
  int tn;
  scanf ("%d", &tn);
  for (int tt = 0; tt < tn; tt++) {
    int n;
    scanf ("%d", &n);
    puts (n % 8 ? "First" : "Second");
  }
  return 0;
}

Problem solution in C.

#include <assert.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int t;
    scanf("%d ",&t);
    
    while(t--)
    {
        int n;
        scanf("%d ",&n);
     
            if(n%8==0)
            printf("Secondn");
            else 
            printf("Firstn");
        
    }
}

Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes