cutting recipes

t=int(input())

i=0

if(t<=100):

for i in range(t):

    f=[]
    f= list(map(int, input().split()))
    l=f[0]
    if((l>=2)and(l<=50)):
         f.remove(f[0])
         def gcd(x,y):
             rem=x%y
             while(rem!=0):
                 x=y
                 y=rem
                 rem=x%y
             return y
         
             j=0
    for j in range(l-1):
        a=gcd(f[j],f[j+1])
        if(a==1):
            break
        new=' '
    for j in range(l):
        ele=f[j]//a
        new+=str(ele)+' '
    print(new.strip())

whats wrong with this code!!!

You are calculating the gcd of two consecutive elements in an array but u r supposed to calculate the gcd of all the elements in the given array

change this line

    a=gcd(f[j],f[j+1])

to

    a=gcd(a,f[j])

where a = f[1] and iterate through complete array

this is ur correted code:

t=int(input())
for i in range(t):


   	f= [int(x) for x in raw_input().split()]
        def gcd(x,y):
            rem=x%y
            while(rem!=0):
                x=y
                y=rem
                rem=x%y
            return y
	l = f[0]
	a = f[1]
    	for x in f[1:]:
    	    a=gcd(a,x)
    	    if(a==1):
            	break
        new=' '
        for j in range(1,l+1):
      		ele=f[j]//a
      	 	new+=str(ele)+' '
    	print(new.strip())
//