using
System;
using
System.Collections.Generic;
class
GFG
{
class
pair : IComparable<pair>
{
public
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
public
int
CompareTo(pair p)
{
return
this
.second-p.first;
}
}
static
bool
isComposite(
int
n)
{
if
(n <= 1)
return
false
;
if
(n <= 3)
return
false
;
if
(n % 2 == 0 || n % 3 == 0)
return
true
;
for
(
int
i = 5; i * i <= n; i = i + 6)
if
(n % i == 0 || n % (i + 2) == 0)
return
true
;
return
false
;
}
static
int
digitProduct(
int
number)
{
int
product = 1;
while
(number > 0)
{
product *= (number % 10);
number /= 10;
}
return
product;
}
static
bool
compositedigitProduct(
int
num)
{
int
res = digitProduct(num);
if
(res == 1) {
return
false
;
}
if
(isComposite(res)) {
return
true
;
}
return
false
;
}
static
int
largestCompositeDigitProduct(
int
[]a,
int
n,
int
k)
{
List<pair> pq =
new
List<pair>();
for
(
int
i = 0; i < n; i++)
{
if
((i % k) == 0)
{
continue
;
}
if
(compositedigitProduct(a[i]))
{
int
b = digitProduct(a[i]);
pq.Add(
new
pair(b, a[i]));
}
}
pq.Sort();
return
pq[pq.Count - 1].second;
}
public
static
void
Main(String[] args)
{
int
[]arr = { 233, 144, 89, 71, 13,
21, 11, 34, 55, 23 };
int
n = arr.Length;
int
k = 3;
int
ans = largestCompositeDigitProduct(
arr, n, k);
Console.Write(ans +
"\n"
);
}
}