-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
38bce9d
commit 3d843cb
Showing
5 changed files
with
282 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# <p align="center">Cuban Prime Checker</p> | ||
|
||
## Description :- | ||
|
||
Cuban Prime Checker is a web application that allows users to identify and find Cuban prime numbers within a specified range. | ||
|
||
* Checks if a number is a Cuban prime. | ||
* Finds Cuban prime numbers within a specified range. | ||
|
||
## What is a Cuban Prime? | ||
|
||
A Cuban prime is a prime number that is a solution to the Diophantine equation x^3 + y^3 = z^3 + 1, where x, y, and z are positive integers. In other words, it's a special type of prime number related to the sum of cubes. | ||
|
||
For example, 2, 19, 37 are Cuban primes as they satisfy the mentioned Diophantine equation. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
|
||
## Screenshots :- | ||
![Cuban](https://github.com/Rakesh9100/CalcDiverse/assets/125949765/61d9e288-e8bd-4be2-8a09-babb2bac3f1b) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="style.css"> | ||
<title>Cuban Prime Calculator</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1 class="title">Cuban Prime Calculator</h1> | ||
<div class="information"> | ||
<h2>What is a Cuban Prime?</h2> | ||
<p> | ||
A Cuban prime is a prime number that is a solution to the Diophantine equation <em>x^3 + y^3 = z^3 + 1</em>, where x, y, and z are positive integers. | ||
It's a special type of prime number related to the sum of cubes. | ||
</p> | ||
|
||
<h2>Formula:</h2> | ||
<p> | ||
The Diophantine equation for Cuban primes is <em>x^3 + y^3 = z^3 + 1</em>. | ||
</p> | ||
|
||
<h2>Solution Process:</h2> | ||
<p> | ||
When checking a number for Cuban primality, the application verifies if the given number satisfies the Diophantine equation. | ||
The application then checks if both the calculated value and the given number are prime. If the conditions are met, the number is identified as a Cuban Prime. | ||
</p> | ||
</div> | ||
<div class="calculator"> | ||
<div class="section"> | ||
<p class="calculator-title">Check Single Cuban Prime</p> | ||
<label for="number">Enter a number:</label> | ||
<input type="number" id="number" placeholder="Enter a number"> | ||
<button onclick="checkCubanPrime()">Check</button> | ||
<p id="resultSingle"></p> | ||
</div> | ||
|
||
<div class="section"> | ||
<p class="calculator-title">Check Cuban Primes in Range</p> | ||
<label for="fromRange">From:</label> | ||
<input type="number" id="fromRange" placeholder="Enter from number"> | ||
<label for="toRange">To:</label> | ||
<input type="number" id="toRange" placeholder="Enter to number"> | ||
<button onclick="checkCubanPrimesInRange()">Check</button> | ||
<p id="rangeResult"></p> | ||
</div> | ||
</div> | ||
|
||
|
||
|
||
<script src="script.js"></script> | ||
</body> | ||
|
||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function isPrime(num) { | ||
if (num < 2) { | ||
return false; | ||
} | ||
for (let i = 2; i <= num / 2; i++) { | ||
if (num % i === 0) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function cubeOfNum(num) { | ||
return num * num * num; | ||
} | ||
|
||
function isCubanPrime(num) { | ||
let res = cubeOfNum(num) - cubeOfNum(num - 1); | ||
return isPrime(res) && isPrime(num); | ||
} | ||
|
||
function getCubanSolution(num) { | ||
let res = cubeOfNum(num) - cubeOfNum(num - 1); | ||
return `<br>The cube of ${num} is ${cubeOfNum(num)}.<br>The cube of ${num - 1} is ${cubeOfNum(num - 1)}.<br>The difference is ${res}.<br>This number is Cuban Prime because both ${num} and ${res} are prime.`; | ||
} | ||
|
||
function checkCubanPrime() { | ||
let number = document.getElementById('number').value; | ||
|
||
if (!validateInput(number)) { | ||
alert('Please enter a valid positive integer.'); | ||
return; | ||
} | ||
|
||
let result = isCubanPrime(parseInt(number)); | ||
let message = result ? `${number} is a Cuban Prime number. ${getCubanSolution(parseInt(number))}` : `${number} is not a Cuban Prime number.`; | ||
|
||
document.getElementById('resultSingle').innerHTML = `<span class="${result ? 'cuban-prime' : 'not-cuban-prime'}">${message}</span>`; | ||
} | ||
|
||
function checkCubanPrimesInRange() { | ||
let fromRange = parseInt(document.getElementById('fromRange').value); | ||
let toRange = parseInt(document.getElementById('toRange').value); | ||
|
||
if (isNaN(fromRange) || isNaN(toRange) || fromRange >= toRange) { | ||
alert('Please enter valid range values.'); | ||
return; | ||
} | ||
|
||
let cubanPrimes = []; | ||
|
||
for (let i = fromRange; i <= toRange; i++) { | ||
if (isCubanPrime(i)) { | ||
cubanPrimes.push(i); | ||
} | ||
} | ||
|
||
if (cubanPrimes.length > 0) { | ||
document.getElementById('rangeResult').innerHTML = `<span class="cuban-prime-result">Cuban Prime numbers in the range ${fromRange} to ${toRange}: ${cubanPrimes.join(', ')}</span>`; | ||
} else { | ||
document.getElementById('rangeResult').innerHTML = `There are no Cuban Prime numbers in the range ${fromRange} to ${toRange}.`; | ||
} | ||
} | ||
|
||
function validateInput(number) { | ||
return /^(0|[1-9]\d*)$/.test(number); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
body { | ||
font-family: 'Roboto', sans-serif; | ||
text-align: center; | ||
margin: 0; | ||
padding: 0; | ||
background: linear-gradient(135deg, #2980B9, #6DD5FA); | ||
color: #fff; | ||
} | ||
|
||
.calculator { | ||
display: flex; | ||
justify-content: space-around; | ||
align-items: flex-start; | ||
margin: 50px auto; | ||
max-width: 900px; | ||
} | ||
|
||
.section { | ||
width: 45%; | ||
padding: 20px; | ||
box-sizing: border-box; | ||
background: linear-gradient(45deg, #1E2A39, #394A5E); | ||
border: 1px solid #00f; | ||
border-radius: 15px; | ||
box-shadow: 0 0 20px rgba(255, 255, 255, 0.8); | ||
margin-bottom: 20px; | ||
} | ||
|
||
input { | ||
padding: 10px; | ||
font-size: 16px; | ||
margin-top: 10px; | ||
width: 100%; | ||
box-sizing: border-box; | ||
background-color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
background-color: #3498DB; | ||
color: #fff; | ||
border: none; | ||
border-radius: 5px; | ||
margin-top: 10px; | ||
transition: background-color 0.3s, box-shadow 0.3s; | ||
} | ||
|
||
button:hover { | ||
background-color: #2980B9; | ||
box-shadow: 0 0 20px rgba(255, 255, 255, 0.8); | ||
} | ||
|
||
p { | ||
font-size: 18px; | ||
margin-top: 20px; | ||
color: #fff; | ||
} | ||
.cuban-prime-result { | ||
color: #2ECC71; | ||
} | ||
|
||
.title { | ||
padding: 20px; | ||
margin: 0; | ||
font-size: 36px; | ||
font-weight: 900; | ||
color: #FFC300; | ||
transition: color 0.3s, transform 0.3s; | ||
} | ||
|
||
.title:hover { | ||
color: #E74C3C; | ||
transform: scale(1.1); | ||
} | ||
|
||
.calculator-title { | ||
color: #2ECC71; | ||
font-size: 24px; | ||
font-weight: bold; | ||
margin-bottom: 15px; | ||
} | ||
|
||
.information { | ||
text-align: justify; | ||
margin-top: 30px; | ||
color: #fff; | ||
max-width: 800px; | ||
margin-left: auto; | ||
margin-right: auto; | ||
border: 1px solid #00f; | ||
border-radius: 15px; | ||
padding: 20px; | ||
box-shadow: 0 0 20px rgba(255, 255, 255, 0.8); | ||
} | ||
|
||
|
||
.information h2 { | ||
color: #FFC300; | ||
font-size: 24px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.information p { | ||
font-size: 16px; | ||
line-height: 1.6; | ||
margin-bottom: 20px; | ||
} | ||
.cuban-prime { | ||
color: #2ECC71; } | ||
|
||
.not-cuban-prime { | ||
color: #E74C3C; | ||
} | ||
.rangeResult{ | ||
color: #2ECC71; | ||
} |
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