To solve this problem, you need to keep track of the number on the board as it is updated by multiplying it with each element from the sequence a
, and after each step, we must check if the resulting number is a perfect square.
Pseudocode:
- Read the input.
- Start with the number
1
on the board. - For each element in the sequence, multiply it with the current number on the board and check if the result is a perfect square.
- Output "yes" or "no" based on whether the current product is a perfect square.
using System;
class PerfectSquareChecker
{
// Helper function to check if a number is a perfect square
static bool IsPerfectSquare(long x)
{
if (x < 0) return false;
long sqrtX = (long)Math.Sqrt(x);
return sqrtX * sqrtX == x;
}
static void Main()
{
// Read the input
int n = int.Parse(Console.ReadLine()); // Number of elements in the sequence
string[] input = Console.ReadLine().Split(); // Sequence of numbers as strings
long[] a = new long[n];
for (int i = 0; i < n; i++)
{
a[i] = long.Parse(input[i]); // Parse each element into a long array
}
// Start with 1 on the board
long currentNumber = 1;
// Process each number in the sequence
for (int i = 0; i < n; i++)
{
currentNumber *= a[i]; // Multiply current number with a[i]
// Check if the current number is a perfect square
if (IsPerfectSquare(currentNumber))
{
Console.WriteLine("yes");
}
else
{
Console.WriteLine("no");
}
}
}
}
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin