Undergrad How do computers evaluate the GCD of two integers?

Click For Summary
Computers evaluate the GCD of two integers primarily using algorithms programmed by developers, with the Euclidean Algorithm being a common choice due to its efficiency. While subtractions are computationally inexpensive, divisions are necessary for optimal performance, especially when the integers differ significantly. Some implementations may combine lookup tables with the Euclidean Algorithm to enhance speed, though this can increase memory usage. Alternative algorithms exist that can compute the GCD faster than the traditional quadratic runtime, particularly for larger inputs. Overall, the choice of algorithm impacts both speed and resource efficiency in GCD calculations.
matqkks
Messages
282
Reaction score
5
Do they use the Euclidean Algorithm?
 
Mathematics news on Phys.org
Computers do not have minds of their own. A program to evaluate GCD of two integers would be written by a programmer, who would use whatever algorithm he/she feels best.
 
  • Like
Likes berkeman
Check the rosettacode.org site someone may have developed the code in whatever language you are interested in.
 
Here’s the Euclidean algorithm

https://en.m.wikipedia.org/wiki/Euclidean_algorithm

I imagine math software would use this algorithm to compute it as subtractions are relatively cheap compared to multiplications or divisions.

Another remote possibility is it uses a combination of lookup table and Euclidean algorithm to speed things up although that may take up more memory than necessary and depending on the table size more costly time wise.
 
  • Like
Likes Janosh89 and berkeman
jedishrfu said:
I imagine math software would use this algorithm to compute it as subtractions are relatively cheap compared to multiplications or divisions.
You still need some sort of division to calculate how much you have to subtract. Simply subtracting the smaller number from the larger number repeatedly has a really bad worst-case runtime if the numbers are very different (exponential, while divisions make the method scale with the input length squared).

There are alternative algorithms that can compute the GCD faster than quadratic runtime for longer inputs.
 
  • Like
Likes jedishrfu
Here is a little puzzle from the book 100 Geometric Games by Pierre Berloquin. The side of a small square is one meter long and the side of a larger square one and a half meters long. One vertex of the large square is at the center of the small square. The side of the large square cuts two sides of the small square into one- third parts and two-thirds parts. What is the area where the squares overlap?

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
1K
  • · Replies 13 ·
Replies
13
Views
1K
  • · Replies 5 ·
Replies
5
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K