JSFiddle - React, Tailwind, and code Playground
by Josh Pullen
JavaScript
function isPrime(n) {
if (n === 1) return false;
for (let i = 2; i < n; i++) {
if ((n / i) % 1 === 0) {
return false;
}
}
return true;
}
let results = [];
for (let i = 1; i < 60; i++) {
for (let j = 1; j <= 60; j++) {
if (i**2 * j <= 60) {
if (isPrime(i) && isPrime(j)) {
results.push([i, j]);
}
}
}
}
results = results.sort((a, b) => a[0]**2 * a[1] - b[0]**2 * b[1]);
document.body.innerHTML = results
.map(([i, j]) => String.raw`\item $${i**2 * j} = ${i}^2 \cdot ${j}$`)
.join("<br />");