fork download
  1. # your code goes here
  2. from functools import reduce
  3. def allSubArrays(L,L2=None):
  4. if L2==None:
  5. L2 = L[:-1]
  6. if L==[]:
  7. if L2==[]:
  8. return []
  9. return allSubArrays(L2,L2[:-1])
  10. return [L]+allSubArrays(L[1:],L2)
  11. for _ in range(int(input())):
  12. n=int(input())
  13. a=list(map(int,input().split()))
  14. s=dict()
  15. c=0
  16. l=allSubArrays(a)
  17. for j in l:
  18. x=y=-1
  19. q=reduce((lambda u,v: u * v), j)
  20. for i in range(q+1):
  21. if i * i >= q:
  22. x=i
  23. break
  24. s[i * i] = 1
  25. if (i * i-q) in s.keys():
  26. y=int((i * i - q)**(1 / 2))
  27. if x>=0 and y>=0:
  28. c+=1
  29. print(c)
Success #stdin #stdout 0.02s 9308KB
stdin
2
3
1 2 3
3
2 5 6
stdout
2
2