using
System;
using
System.Collections.Generic;
class
GFG {
static
int
getValue(Dictionary<
int
,
int
> dict,
int
val,
int
defaultVal)
{
if
(dict.ContainsKey(val))
return
dict[val];
return
defaultVal;
}
static
int
Combinations(
int
x,
int
y,
int
z,
Dictionary<
int
,
int
> count)
{
int
valx = getValue(count, x, 0);
int
valy = getValue(count, y, 0);
int
valz = getValue(count, z, 0);
if
(x == y) {
if
(y == z) {
return
(valx * (valy - 1) * (valz - 2)) / 6;
}
else
{
return
((((valy - 1) * valx) / 2) * valz);
}
}
else
if
(y == z) {
return
valx * (((valz - 1) * valy) / 2);
}
else
{
return
(valx * valy * valz);
}
}
public
static
void
Main(
string
[] args)
{
int
target = 93;
int
[] ar = { 1, 31, 3, 1, 93, 3, 31, 1, 93 };
int
N = ar.Length;
List<
int
> list =
new
List<
int
>();
for
(
int
i = 0; i < N; i++)
if
(ar[i] != 0 && target % ar[i] == 0)
list.Add(ar[i]);
list.Sort();
int
length = list.Count;
int
[] arr = list.ToArray();
Dictionary<
int
,
int
> count
=
new
Dictionary<
int
,
int
>();
HashSet<
string
> tripletSeen =
new
HashSet<
string
>();
foreach
(
int
val
in
list) count[val]
= getValue(count, val, 0) + 1;
int
totalCount = 0;
for
(
int
i = 0; i < length - 2; i++) {
for
(
int
j = i + 1; j < length - 1; j++) {
if
(target % (arr[i] * arr[j]) == 0) {
int
toFind = target / (arr[i] * arr[j]);
int
[] a = { arr[i], arr[j], toFind };
Array.Sort(a);
string
str
= (a[0] +
"#"
+ a[1] +
"#"
+ a[2]);
if
(toFind >= arr[i] && toFind >= arr[j]
&& tripletSeen.Contains(str)
==
false
) {
tripletSeen.Add(str);
totalCount += Combinations(
arr[i], arr[j], toFind, count);
}
}
}
}
Console.WriteLine(
"Total number of triplets found: "
+ totalCount);
}
}