EPS/04-03-24/a.py

27 lines
520 B
Python
Raw Normal View History

2024-03-04 16:25:39 +01:00
import math
def are_coprime(a, b):
return math.gcd(a, b) == 1
def find_greatest():
input()
alist = [int(a) for a in input().split()]
mapping = {}
for i in range(len(alist)):
mapping[alist[i]] = i
maxi = -1
for a in mapping:
for b in mapping:
if mapping[a]+mapping[b]+2 > maxi and are_coprime(a, b):
maxi = mapping[a]+mapping[b]+2
return maxi
def main():
nb = int(input())
for i in range(nb):
print(find_greatest())
main()