-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
96 lines (88 loc) · 2.79 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IntrepidBird | IntrepidPrimes</title>
<!-- Favicon -->
<link rel="icon" href="favicon.png">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<!-- Custom CSS -->
<style>
body {
background-color: #f1f8ff;
}
.container {
margin-top: 50px;
}
h1 {
color: #007bff;
text-align: center;
}
.form-group {
margin-bottom: 20px;
}
.result {
margin-top: 30px;
text-align: center;
}
.result h3 {
color: #007bff;
}
</style>
</head>
<body>
<div class="container">
<h1>Mersenne Primes Calculator</h1>
<form id="mersenneForm">
<div class="form-group">
<label for="limit">Enter the limit:</label>
<input type="number" class="form-control" id="limit" placeholder="Enter n, where the limit will then be 2^n" required>
</div>
<button type="submit" class="btn btn-primary">Calculate</button>
</form>
<div class="result">
<h3>Result:</h3>
<p id="resultText"></p>
</div>
</div>
<!-- Bootstrap & jQuery JS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
<!-- Custom JS -->
<script>
$(document).ready(function() {
$('#mersenneForm').submit(function(e) {
e.preventDefault();
var limit = parseInt($('#limit').val());
var result = calculateMersennePrimes(limit);
$('#resultText').text(result.join(', '));
});
function calculateMersennePrimes(limit) {
var primes = [];
for (var i = 2; i <= limit; i++) {
if (isPrime(i)) {
var mersenne = Math.pow(2, i) - 1;
if (isPrime(mersenne)) {
primes.push(mersenne);
}
}
}
return primes;
}
function isPrime(num) {
if (num <= 1) {
return false;
}
for (var i = 2; i <= Math.sqrt(num); i++) {
if (num % i === 0) {
return false;
}
}
return true;
}
});
</script>
</body>
</html>