Problem p02574 (python)

Fixed submission:
#ceilevenoddformula
import math
import bisect
import copy
import time
from collections import Counter
from itertools import combinations
#map(int,input().split())
#int(x) for x in input().split()
def gcd(a, b) : 
    if (a == 0) : 
        return b 
      
    if (b == 0) : 
        return a   
    k = 0
      
    while(((a | b) & 1) == 0) : 
        a = a >> 1
        b = b >> 1
        k = k + 1
          
 
    while ((a & 1) == 0) : 
        a = a >> 1
  
    # From here on, 'a' is always odd.  
    while(b != 0) : 
          
        # If b is even, remove all  
        # factor of 2 in b  
        while ((b & 1) == 0) : 
            b = b >> 1
  
        # Now a and b are both odd. Swap if 
        # necessary so a <= b, then set  
        # b = b - a (which is even). 
        if (a > b) : 
          
            # Swap u and v. 
            temp = a 
            a = b 
            b = temp 
  
        b = (b - a) 
      
    # restore common factors of 2  
    return (a << k) 


def primeFactors(n,l): 
    q=set()    
    f=0
    while n % 2 == 0: 
    	if l[2] and f==0:
    		return False
    	l[2]=True
    	n = n / 2     
    	f=1 

    for i in range(3,int(math.sqrt(n))+1,2): 
        f=0
        while n % i== 0:
        	if l[i] and f==0:
        		return False
        	l[i]=True
        	n = n / i 
        	f=1
              
    if n > 2: 
    	if l[n]:
    		return False
    	l[n]=True

    #l=l.union(q)
    return True

n=int(input())
l=[int(x) for x in input().split()]
#l.sort()
d={i:False for i in range(1,max(l)+1)}
ans=1
for i in range(n):
	f=primeFactors(l[i],d)
	if not f:
		ans=0
		break



if ans:
	print('pairwise coprime')
else:
	a=l[0]
	b=l[1]
	gc=gcd(a,b)
	for i in range(2,n):
		gc=gcd(gc,l[i])
		if gc==1:
			break
	if gc==1:
		print('setwise coprime')
	else:
		print('not coprime')

Buggy submission (verdict: Runtime Error):
#ceilevenoddformula
import math
import bisect
import copy
import time
from collections import Counter
from itertools import combinations
#map(int,input().split())
#int(x) for x in input().split()
def gcd(a, b) : 
    if (a == 0) : 
        return b 
      
    if (b == 0) : 
        return a   
    k = 0
      
    while(((a | b) & 1) == 0) : 
        a = a >> 1
        b = b >> 1
        k = k + 1
          
 
    while ((a & 1) == 0) : 
        a = a >> 1
  
    # From here on, 'a' is always odd.  
    while(b != 0) : 
          
        # If b is even, remove all  
        # factor of 2 in b  
        while ((b & 1) == 0) : 
            b = b >> 1
  
        # Now a and b are both odd. Swap if 
        # necessary so a <= b, then set  
        # b = b - a (which is even). 
        if (a > b) : 
          
            # Swap u and v. 
            temp = a 
            a = b 
            b = temp 
  
        b = (b - a) 
      
    # restore common factors of 2  
    return (a << k) 


def primeFactors(n,l): 
    q=set()    
    f=0
    while n % 2 == 0: 
    	if l[2] and f==0:
    		return False
    	l[2]=True
    	n = n / 2     
    	f=1 

    for i in range(3,int(math.sqrt(n))+1,2): 
    	f=0
        while n % i== 0:
        	if l[i] and f==0:
        		return False
        	l[i]=True
        	n = n / i 
        	f=1
              
    if n > 2: 
    	if l[n]:
    		return False
    	l[n]=True

    #l=l.union(q)
    return True

n=int(input())
l=[int(x) for x in input().split()]
#l.sort()
d={i:False for i in range(1,max(l)+1)}
ans=1
for i in range(n):
	f=primeFactors(l[i],d)
	if not f:
		ans=0
		break



if ans:
	print('pairwise coprime')
else:
	a=l[0]
	b=l[1]
	gc=gcd(a,b)
	for i in range(2,n):
		gc=gcd(gc,l[i])
		if gc==1:
			break
	if gc==1:
		print('setwise coprime')
	else:
		print('not coprime')