Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Cuban Prime Calculator #603

Merged
merged 9 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Calculators/Cuban-Prime-Calculator/READMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# <p align="center">Cuban Prime Number Calculator</p>

## Description :-

This calculator will help you convert your input data sizes in following sizes
Bits, Nibbles,Bytes,Kilobytes,Megabytes,Gigabytes,Terabytes,Petabytes,Exabytes,Zetabytes,Yottabytes

## Tech Stack :-

- HTML
- CSS
- JavaScript

## Screenshots :-
![Cuban](https://github.com/Rakesh9100/CalcDiverse/assets/125949765/61d9e288-e8bd-4be2-8a09-babb2bac3f1b)
38 changes: 38 additions & 0 deletions Calculators/Cuban-Prime-Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!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="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>
61 changes: 61 additions & 0 deletions Calculators/Cuban-Prime-Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
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 checkCubanPrime() {
let number = document.getElementById('number').value;

if (!validateInput(number)) {
alert('Please enter a valid positive integer.');
return;
}

let result = isCubanPrime(parseInt(number));

document.getElementById('resultSingle').innerText = `${number} is ${result ? '' : 'not '}a Cuban Prime number.`;
}

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').innerText = `Cuban Prime numbers in the range ${fromRange} to ${toRange}: ${cubanPrimes.join(', ')}`;
} else {
document.getElementById('rangeResult').innerText = `There are no Cuban Prime numbers in the range ${fromRange} to ${toRange}.`;
}
}

function validateInput(number) {
return /^(0|[1-9]\d*)$/.test(number);
}
82 changes: 82 additions & 0 deletions Calculators/Cuban-Prime-Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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;
}

.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;
}
15 changes: 15 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1836,6 +1836,21 @@ <h3>Checks if a number is circular prime and finds circular prime numbers in a r
</div>
</div>
</div>

<div class="box">
<div class="content">
<h2>Cuban Prime Number Calculator</h2>
<h3>Checks if a number is cuban prime or not and finds cuban prime numbers in a range.</h3>
<div class="card-footer">
<a href="./Calculators/Cuban-Prime-Calculator/index.html" target="_blank">
<button>Try Now</button>
</a>
<a href="https://github.com/Rakesh9100/CalcDiverse/tree/main/Calculators/Cuban-Prime-Calculator" title="Source Code" target="_blank">
<img src="./assets/images/github.png" alt="Source Code"></img>
</a>
</div>
</div>
</div>
</div>

<!-- Calculator Section Ends Here -->
Expand Down
Loading