From 3d843cb0e563377ae8a88917db10e1567c4bc313 Mon Sep 17 00:00:00 2001 From: Aftab Mankapure <125949765+AftabMankapure@users.noreply.github.com> Date: Sun, 25 Feb 2024 00:41:38 +0530 Subject: [PATCH] Added Cuban Prime Calculator (#603) --- Calculators/Cuban-Prime-Calculator/README.md | 24 ++++ Calculators/Cuban-Prime-Calculator/index.html | 57 +++++++++ Calculators/Cuban-Prime-Calculator/script.js | 67 ++++++++++ Calculators/Cuban-Prime-Calculator/style.css | 120 ++++++++++++++++++ index.html | 14 ++ 5 files changed, 282 insertions(+) create mode 100644 Calculators/Cuban-Prime-Calculator/README.md create mode 100644 Calculators/Cuban-Prime-Calculator/index.html create mode 100644 Calculators/Cuban-Prime-Calculator/script.js create mode 100644 Calculators/Cuban-Prime-Calculator/style.css diff --git a/Calculators/Cuban-Prime-Calculator/README.md b/Calculators/Cuban-Prime-Calculator/README.md new file mode 100644 index 000000000..8c5f168b8 --- /dev/null +++ b/Calculators/Cuban-Prime-Calculator/README.md @@ -0,0 +1,24 @@ +#

Cuban Prime Checker

+ +## 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) diff --git a/Calculators/Cuban-Prime-Calculator/index.html b/Calculators/Cuban-Prime-Calculator/index.html new file mode 100644 index 000000000..7262663f5 --- /dev/null +++ b/Calculators/Cuban-Prime-Calculator/index.html @@ -0,0 +1,57 @@ + + + + + + + + Cuban Prime Calculator + + + + +

Cuban Prime Calculator

+
+

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. + It's a special type of prime number related to the sum of cubes. +

+ +

Formula:

+

+ The Diophantine equation for Cuban primes is x^3 + y^3 = z^3 + 1. +

+ +

Solution Process:

+

+ 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. +

+
+
+
+

Check Single Cuban Prime

+ + + +

+
+ +
+

Check Cuban Primes in Range

+ + + + + +

+
+
+ + + + + + + diff --git a/Calculators/Cuban-Prime-Calculator/script.js b/Calculators/Cuban-Prime-Calculator/script.js new file mode 100644 index 000000000..6b6224c1e --- /dev/null +++ b/Calculators/Cuban-Prime-Calculator/script.js @@ -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 `
The cube of ${num} is ${cubeOfNum(num)}.
The cube of ${num - 1} is ${cubeOfNum(num - 1)}.
The difference is ${res}.
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 = `${message}`; +} + +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 = `Cuban Prime numbers in the range ${fromRange} to ${toRange}: ${cubanPrimes.join(', ')}`; + } 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); +} diff --git a/Calculators/Cuban-Prime-Calculator/style.css b/Calculators/Cuban-Prime-Calculator/style.css new file mode 100644 index 000000000..93be44348 --- /dev/null +++ b/Calculators/Cuban-Prime-Calculator/style.css @@ -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; +} diff --git a/index.html b/index.html index 486bd6615..8307ae23a 100644 --- a/index.html +++ b/index.html @@ -1883,6 +1883,20 @@

Calculates the time in which you can payoff your Credits.

+
+
+

Cuban Prime Calculator

+

Checks if a number is cuban prime or not and finds cuban prime numbers in a range.

+ +
+