using
System;
using
System.Collections.Generic;
public
class
Pair<U, V> {
public
readonly
U first;
public
readonly
V second;
public
Pair(U first, V second)
{
this
.first = first;
this
.second = second;
}
}
public
class
GFG {
static
List<
int
> NumOfPrimeFacts(
int
n)
{
List<
int
> a =
new
List<
int
>();
if
(n == 1) {
a.Add(0);
return
a;
}
for
(
int
i = 2; (i * i) <= n; i++) {
while
(n % i == 0) {
a.Add(i);
n = n / i;
}
}
if
(n > 1)
a.Add(n);
return
a;
}
static
int
GreatestPrimeFact(List<
int
> v)
{
int
ans = 0;
for
(
int
i = 0; i < v.Count; i++)
if
(v[i] > ans)
ans = v[i];
return
ans;
}
static
List<Pair<
int
,
int
> > ReturnPair(
int
[] arr,
int
n)
{
List<Pair<
int
,
int
> > vec
=
new
List<Pair<
int
,
int
> >();
for
(
int
i = 0; i < n; i++) {
for
(
int
j = i + 1; j < n; j++) {
Pair<
int
,
int
> p
=
new
Pair<
int
,
int
>(arr[i], arr[j]);
int
val = arr[i] ^ arr[j];
int
diffOfPair = Math.Abs(arr[i] - arr[j]);
List<
int
> a = NumOfPrimeFacts(val);
int
largestPrimeFact = GreatestPrimeFact(a);
if
(largestPrimeFact > diffOfPair)
vec.Add(p);
}
}
return
vec;
}
static
public
void
Main()
{
int
[] arr = { 9, 6, 4, 8 };
int
n = 4;
List<Pair<
int
,
int
> > vec = ReturnPair(arr, n);
Console.WriteLine(
"The number of such pairs is "
+ vec.Count);
Console.WriteLine(
"The pair(s) is/are :"
);
Console.Write(
"["
);
for
(
int
i = 0; i < vec.Count; i++) {
Console.Write(
" ( "
+ vec[i].first +
", "
+ vec[i].second +
" ) "
);
}
Console.WriteLine(
"]"
);
}
}