GCD Exploration

Sort by

recency

|

14 Discussions

|

  • + 0 comments

    include

    include

    int main(){ unsigned long long int N,a,b,k,x,y=0,z=0,i; scanf("%lld %lld %lld",&N,&a,&b); while (b!=0) { k=b; b=a%b; a=k; } x=N; while (x!=0) { x=x/10; y++; } for (i=1;i<=a;i++) printf ("%lld",N); }

  • + 0 comments
    BigInteger gcd(BigInteger n)
    
  • + 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)
    
  • + 0 comments

    Learned new thing :) thnx

  • + 1 comment

    I am using java to solve this problem. First test case ran successfully. However, I get 'Terminated due to timeout' error for all other test cases. If anyone has solved this using Java, then please suggest the solution that run faster.