using
System;
using
System.Collections.Generic;
class
GFG
{
public
class
pair
{
public
int
first, second;
public
pair(
int
first,
int
second)
{
this
.first = first;
this
.second = second;
}
}
static
bool
isPerfectSquare(
double
x)
{
double
sr = Math.Sqrt(x);
return
((sr - Math.Floor(sr)) == 0);
}
static
bool
isFibonacci(
int
n)
{
return
isPerfectSquare(5 * n * n + 4) ||
isPerfectSquare(5 * n * n - 4);
}
static
int
totalPairs(
int
[]a,
int
[]b,
int
n,
int
m)
{
List<pair> s =
new
List<pair>();
for
(
int
i = 0; i < n; i++)
{
for
(
int
j = 0; j < m; j++)
{
if
(isFibonacci(a[i] + b[j]) ==
true
)
{
if
(a[i] < b[j])
{
if
(checkDuplicate(s,
new
pair(a[i], b[j])))
s.Add(
new
pair(a[i], b[j]));
}
else
{
if
(checkDuplicate(s,
new
pair(b[j], a[i])))
s.Add(
new
pair(b[j], a[i]));
}
}
}
}
return
s.Count;
}
static
bool
checkDuplicate(List<pair> pairList,
pair newPair)
{
foreach
(pair p
in
pairList)
{
if
(p.first == newPair.first &&
p.second == newPair.second)
return
false
;
}
return
true
;
}
public
static
void
Main(String[] args)
{
int
[]a = { 99, 1, 33, 2 };
int
[]b = { 1, 11, 2 };
int
n = a.Length;
int
m = b.Length;
Console.WriteLine(totalPairs(a, b, n, m));
}
}