using
System;
using
System.Collections.Generic;
using
System.Linq;
public
class
GFG
{
static
List<List<
int
>> sieve_of_eratosthenes(
int
n)
{
List<List<
int
>> divisors =
new
List<List<
int
>>();
for
(
int
i = 0; i <= n; i++)
{
divisors.Add(
new
List<
int
>());
}
for
(
int
i = 1; i <= n; i++)
{
for
(
int
j = i; j <= n; j += i)
{
divisors[j].Add(i);
}
}
return
divisors;
}
static
void
product_of_proper_divisors(
int
[] arr,
int
Q)
{
List<List<
int
>> divisors = sieve_of_eratosthenes(arr.Max());
for
(
int
i = 0; i < Q; i++)
{
int
n = arr[i];
int
product = 1;
for
(
int
j = 0; j < divisors[n].Count - 1; j++)
{
product *= divisors[n][j];
}
Console.WriteLine(product);
}
}
public
static
void
Main(
string
[] args)
{
int
[] arr = { 4, 6, 8, 16 };
int
Q = arr.Length;
Console.Write(
"Input: Q = "
+ Q +
", arr[] = {"
);
for
(
int
i = 0; i < Q - 1; i++)
{
Console.Write(arr[i] +
", "
);
}
Console.WriteLine(arr[Q - 1] +
"}"
);
Console.WriteLine(
"Output:"
);
product_of_proper_divisors(arr, Q);
int
[] arr2 = { 3, 6, 9, 12 };
Q = arr2.Length;
Console.Write(
"Input: Q = "
+ Q +
", arr[] = {"
);
for
(
int
i = 0; i < Q - 1; i++)
{
Console.Write(arr2[i] +
", "
);
}
Console.WriteLine(arr2[Q - 1] +
"}"
);
Console.WriteLine(
"Output:"
);
product_of_proper_divisors(arr2, Q);
}
}