Skip to content

Latest commit

 

History

History

reversing-euclids-gcd-parameters-out-of-results

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Your main goal is to find two numbers(>= 0), the greatest common divisor of which will be divisor and number of iterations, taken by Euclid's algorithm will be iterations.

Euclid's GCD

BigInteger FindGCD(BigInteger a, BigInteger b) {
  // Swaping `a` and `b`
  if (a < b) {
    a += b;
    b = a - b;
    a = a - b;
  }
  
  while (b > 0) {
    // Iteration of calculation
    BigInteger c = a % b;
    a = b;
    b = c;
  }
  
  // `a` - is greates common divisor now
  return a;
}

Restrictions

Your program should work with numbers

0 < divisor < 1000

0 <= iterations <= 50'000