```python
def gcd(x, y):
    """
    Calculates the greatest common divisor of two positive integers
    using the Euclidean algorithm.
    """
    while y:
        x, y = y, x % y
    return x
```