Created
April 5, 2024 16:26
-
-
Save santocyber/e79bcd5779133b756403c818eb711a24 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Conjectura de Legendre</title> | |
<style> | |
body { | |
font-family: Arial, sans-serif; | |
background-color: #f3f3f3; | |
margin: 0; | |
padding: 0; | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 100vh; | |
} | |
.container { | |
background-color: #fff; | |
border-radius: 10px; | |
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | |
padding: 20px; | |
text-align: center; | |
} | |
h1 { | |
margin-top: 0; | |
color: #333; | |
} | |
p { | |
margin: 10px 0; | |
color: #666; | |
} | |
.highlight { | |
color: #ff5733; /* Destaque em laranja */ | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Conjectura de Legendre</h1> | |
<div id="legendreOutput"></div> | |
</div> | |
<script> | |
let legendrePairs = []; // Lista para armazenar os pares de quadrados primos já calculados | |
function isPrime(num) { | |
if (num <= 1) return false; | |
if (num <= 3) return true; | |
if (num % 2 === 0 || num % 3 === 0) return false; | |
for (let i = 5; i * i <= num; i += 6) { | |
if (num % i === 0 || num % (i + 2) === 0) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function getNextPrimeSquarePair(start) { | |
let n = start; | |
while (true) { | |
let square = n * n; | |
let primeSquare = square + 1; | |
if (isPrime(primeSquare)) { | |
return [n, primeSquare]; | |
} | |
n++; | |
} | |
} | |
function displayNextLegendrePair() { | |
let [n, primeSquare] = getNextPrimeSquarePair(legendrePairs.length === 0 ? 1 : legendrePairs[legendrePairs.length - 1][0] + 1); | |
legendrePairs.push([n, primeSquare]); | |
let outputDiv = document.getElementById('legendreOutput'); | |
let square = n * n; | |
let nextSquare = (n + 1) * (n + 1); | |
let html = `<p>Conjectura de Legendre para ${n}:</p>`; | |
html += `<p>Entre ${square} e ${nextSquare}: <span class="${isPrime(primeSquare) ? 'highlight' : ''}">${primeSquare}</span> ${isPrime(primeSquare) ? 'é primo' : 'não é primo'}</p>`; | |
outputDiv.innerHTML = html; | |
} | |
displayNextLegendrePair(); // Exiba o primeiro par de quadrados primos ao carregar | |
setInterval(displayNextLegendrePair, 1000); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment