o3-mini· OpenAI
LMArena Human Preference 140K
Can you write code to determine if two numbers are co-primes or not?
- User
Can you write code to determine if two numbers are co-primes or not?
- Assistant
Below is an example in Python that uses the Euclidean algorithm to compute the greatest common divisor (GCD) and then checks if it is 1 (which means the two numbers are co-prime):
def gcd(a, b): """Compute the Greatest Common Divisor of a and b.""" while b: a, b = b, a % b return a def are_coprime(a, b): """Return True if a and b are co-prime, False otherwise.""" return gcd(a, b) == 1 # Example usage: num1 = int(input("Enter the first number: ")) num2 = int(input("Enter the second number: ")) if are_coprime(num1, num2): print(f"{num1} and {num2} are co-prime.") else: print(f"{num1} and {num2} are not co-prime.")Explanation
- gcd(a, b): This function calculates the greatest common divisor using the Euclidean algorithm.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.