Opening the reading…
Opening the reading…
DSA FUNDAMENTALS › MATH BASICS
The label composite belongs to one number at a time. The label co-prime belongs to a pair. For the pair 14 and 25, both numbers are composite, but they do not share any factor greater than 1. Their GCD is 1, so the pair is co-prime.
These labels answer different questions. Asking whether 14 or 25 is prime examines one number. Asking whether 14 and 25 are co-prime examines what the two numbers share. A pair does not need to contain prime numbers to be co-prime.
Can 14 and 25 be co-prime even though both numbers are composite?
Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
The complete decision rule is simple: calculate the GCD of the two numbers and check whether it equals 1. For 14 and 25, gcd(14, 25) = 1, so the answer is co-prime.
The result depends only on the shared GCD. It does not depend on whether 14 is prime, whether 25 is prime, or whether either number is composite. A GCD of 1 means the pair has no shared factor greater than 1, which is exactly the condition being tested.
A checker needs one GCD calculation and one boolean condition. Store the result, compare it with 1, and use that comparison as the answer. The GCD is computed once, so the condition directly expresses the definition of co-prime.
#include <iostream>
#include <numeric>
int main() {
int gcdValue = std::gcd(14, 25);
bool coprime = (gcdValue == 1);
std::cout << std::boolalpha << coprime;
}Here gcdValue becomes 1, so coprime becomes true and the program prints true. Testing gcdValue > 1 would identify a shared factor instead of co-primeness. Testing gcdValue == 0 would reject this pair for no relevant reason, and testing the input values themselves would ask about their sizes rather than their shared factors.
Complete the condition using the stored value gcdValue, where gcdValue is gcd(14, 25).
bool coprime = (__________);Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
A checker that requires both inputs to be prime is solving a different problem. It asks whether 14 is prime and 25 is prime, then combines those answers. Both checks are false because both numbers are composite, so that checker rejects the pair.
bool answer = isPrime(14) && isPrime(25);
std::cout << std::boolalpha << answer;For 14 and 25, this code prints false even though gcd(14, 25) is 1. The failure comes from using primality as a substitute for the co-prime rule. To check co-primality, calculate the pair's GCD and compare that result with 1.