BBezoutVale
Workflows

Coding workflows · Bézout integer coefficients

03
Built around your work

A concrete starting point

Return nonnegative gcd and Bézout coefficients for two integers with fewer than 101 decimal digits. Test negative operands and both zero cases, verifying the integer identity and rejecting Boolean inputs.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Bézout integer coefficients

A concrete starting point
def bezout(a, b):
    if any(type(v) is not int or abs(v) >= 10**100 for v in (a, b)):
        raise ValueError("integer.range")
    old_r, r = abs(a), abs(b)
    old_s, s, old_t, t = 1, 0, 0, 1
    while r:
        q = old_r // r
        old_r, r = r, old_r - q * r
        old_s, s = s, old_s - q * s
        old_t, t = t, old_t - q * t
    return old_r, old_s * (-1 if a < 0 else 1), old_t * (-1 if b < 0 else 1)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗