In the 2022 AMC 10A competition, Problem #7 tests prime factor constraints through greatest common divisors and least common multiples:
Contest Problem Statement: "The least common multiple of a positive integer $n$ and $18$ is $180$, and the greatest common divisor of $n$ and $45$ is $15$. What is the sum of the digits of $n$?"
Prime Factor Analysis
Let's look at the prime factorizations of the given numbers:
$18 = 2^1 \times 3^2$
$180 = 2^2 \times 3^2 \times 5^1$
$45 = 3^2 \times 5^1$
$15 = 3^1 \times 5^1$
Now consider what each condition tells us about the prime factors of $n$:
$\text{lcm}(n, 18) = 180$:
The power of $2$ in $180$ is $2^2$. Since $18$ only contributes $2^1$, $n$ must supply $2^2 = 4$.
Furthermore, $180$ has a factor of $5$, which $18$ does not have, so $5$ must also divide $n$.
$\gcd(n, 45) = 15$:
The greatest common divisor has $3^1$, but $45$ has $3^2$. This means $n$ cannot have more than one factor of $3$ (otherwise $\gcd$ would be divisible by $9$). Therefore, the power of $3$ in $n$ must be exactly $3^1$!
In Prolog, we can express the Euclidean algorithm for GCD and the relation $\text{lcm}(a, b) = (a \times b) / \gcd(a, b)$ directly as rules. Then Prolog searches for the positive integer $n$ that simultaneously satisfies both relations!
gcd(A, B, G), lcm(A, B, L) :- gcd(A, 0, A) :- A > 0. gcd(A, B, G) :- B > 0, R is A mod B, gcd(B, R, G). lcm(A, B, L) :- gcd(A, B, G), % LCM formula LCM(A, B) = (A * B) // GCD(A, B): Replace ???? with G
L is (A * B) // ???? .
Move the mouse over a dotted box for more information.
By declaring these fundamental number-theoretic properties, Prolog can search and verify solutions across any range of integers.
Now you try.
Replace ???? with G and click Run to find = 60$ and digit sum $. Then check Example 1 to test GCD and LCM queries directly in the interpreter!
Type your code here:
See your results here:
The code has ???? for the LCM divisor. Replace ???? with G (the greatest common divisor), then click Run to solve the number theory puzzle!
Prolog outputs:
N = 60 SumDigits = 6
This matches option (B) 6 on the 2022 AMC 10A exam.
Share your code
Show a friend, family member, or teacher what you've done!