GCD Exploration

  • + 0 comments

    I don't know why only the first case works even after using the standard gcd function and the euclidean algorithm. Please guide.

    from fractions import gcd
    N,a,b = raw_input().strip().split(' ')
    a,b = [long(a),long(b)]
    ##def hcf(x, y):
    ##  while(y):
    ##      x, y = y, x % y
    ##  return x
    
    temp = N * a
    temp=temp.replace(" ","")
    temp=long(temp)
    
    x = N*b
    x=x.replace(" ","")
    x=long(x)
    
    print gcd(temp,x)