EDIT : For all those who are saying why my brute force c++ (store product and check) , gives WA , this is bcz of overflow of long long int too (for ex take numbers from 1 to 50 means 50! not possible to store)
import math
t=int(input())
for x in range(0,t):
n=int(input())
a=[]
v = map(int, input().split())
v=list(v)
a.append(v[0])
for i in range(1,n):
a.append(a[i-1]*v[i])
z=a[n-1]
for i in range(0,n):
if math.gcd(a[i],int(z/a[i])) ==1:
print(i+1)
break
Can you please tell, whats wrong with this code even for partial points.
My approach-
For every ith index, store the product of elements to the left to it in left[] and to the right of it in right[]. In other words, calculating the prefix and suffix product for each i.
Traversing both arrays, and checking which index the elements are coprime.
Oh , u did same thing i did before 100 marks solution , u store for each index i there is a map in which the prime factorisation stores of all the prime factors of all previous values and current values similarly from reverse side right ?