1 / 2
Jul 2019

This code works correctly on ideone but on submission on spoj it says wrong answer , please tell where i am getting wrong.

def gcd(a,b):
	if(a==0):
		return b
	else:
		return gcd(b%a,a)

t=int(input())
for i in range(0,t):
	n,a,b=input().split()
	a=int(a)
	b=int(b)
	n=int(n)
	h=gcd(a,b)
	
	if(h==1):                          #if the HCF of numbers is 1
		for j in range(a,n):
			if(j%a==0):
				print(j,end=" ")
	else:
		for j in range(a,n):
			if(j%a==0):
				if(j%b!=0):
					print(j,end=" ")
		
		
	print()
  • created

    Jul '19
  • last reply

    Jul '19
  • 1

    reply

  • 742

    views

  • 2

    users

1
350 17 19

I wouldn’t expect to see 323 printed