-
Reduced all possibilities of a number which cannot be prime. Eg: No even number, except 2 can be a prime number, hence we will increment our loop with i+6 jumping and check for i or i+2 to be a factor of the number; if it's a factor then we will return false otherwise true after the loop terminates at the terminating condition which is (i*i<=num)
+
A simple program to check if the given number is Prime or not.
More...
#include <cassert>
#include <iostream>
@@ -113,68 +114,30 @@ Include dependency graph for check_prime.cpp:
Reduced all possibilities of a number which cannot be prime. Eg: No even number, except 2 can be a prime number, hence we will increment our loop with i+6 jumping and check for i or i+2 to be a factor of the number; if it's a factor then we will return false otherwise true after the loop terminates at the terminating condition which is (i*i<=num)
-
Copyright 2020
- Author
- omkarlanghe
-
A simple program to check if the given number if prime or not.
+
A simple program to check if the given number is Prime or not.
+
A prime number is any number that can be divided only by itself and 1. It must be positive and a whole number, therefore any prime number is part of the set of natural numbers. The majority of prime numbers are even numbers, with the exception of 2. This algorithm finds prime numbers using this information. additional ways to solve the prime check problem: https://cp-algorithms.com/algebra/primality_tests.html#practice-problems
- Author
- Omkar Langhe
+-
+ewd00010
-
-
◆ is_prime()
-
-
-
-
-template<typename T >
-
-
- | bool is_prime |
- ( |
- T |
- num | ) |
- |
-
-
-
-
-
for IO operations
-
for assert Function to check if the given number is prime or not.
- Parameters
-
-
- | num | number to be checked. |
-
-
-
-
- Returns
- if number is prime, it returns @ true, else it returns @ false.
-
24 {
-
-
26 if (num <= 1) {
-
27 return false;
-
28 } else if (num == 2 || num == 3) {
-
29 return true;
-
30 } else if ((num % 2) == 0 || num % 3 == 0) {
-
31 return false;
-
32 } else {
-
33 for (T i = 5; (i * i) <= (num); i = (i + 6)) {
-
34 if ((num % i) == 0 || (num % (i + 2) == 0)) {
-
-
36 break;
-
37 }
-
38 }
-
39 }
-
40 return (result);
-
41}
-
uint64_t result(uint64_t n)
Definition fibonacci_sum.cpp:76
-
-
-
◆ main()
@@ -190,32 +153,68 @@ template<typename T >
+
+
+
+
+
+
+ | static void tests |
+ ( |
+ | ) |
+ |
+
+
+ |
+
+static |
+
+
+
+
+
Self-test implementations.
+
- Returns
- void
+
61 {
+
+
+
+
+
+
+
+
+
+
+
72
+
+
74}
+
+
+
bool is_prime(int64_t num)
Function to check if the given number is prime or not.
Definition check_prime.cpp:30
+
+
diff --git a/db/d93/check__prime_8cpp.js b/db/d93/check__prime_8cpp.js
index 37d788d16..548889b3c 100644
--- a/db/d93/check__prime_8cpp.js
+++ b/db/d93/check__prime_8cpp.js
@@ -1,5 +1,6 @@
var check__prime_8cpp =
[
- [ "is_prime", "db/d93/check__prime_8cpp.html#aa18b3517017d99bb4024853bddba5532", null ],
- [ "main", "db/d93/check__prime_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ]
+ [ "is_prime", "db/d93/check__prime_8cpp.html#abd8f794b2229b42876169ff841b6e444", null ],
+ [ "main", "db/d93/check__prime_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ],
+ [ "tests", "db/d93/check__prime_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e", null ]
];
\ No newline at end of file
diff --git a/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.map b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.map
new file mode 100644
index 000000000..ca8d00bf2
--- /dev/null
+++ b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.map
@@ -0,0 +1,7 @@
+
diff --git a/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.md5 b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.md5
new file mode 100644
index 000000000..1e06485d5
--- /dev/null
+++ b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.md5
@@ -0,0 +1 @@
+9c5a2a03b8386cbd80dfb8b3134f2e02
\ No newline at end of file
diff --git a/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg
new file mode 100644
index 000000000..968651279
--- /dev/null
+++ b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg
@@ -0,0 +1,82 @@
+
+
+
+
+
diff --git a/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph_org.svg b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph_org.svg
new file mode 100644
index 000000000..c1178f1f1
--- /dev/null
+++ b/db/d93/check__prime_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph_org.svg
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+tests
+
+
+Node1
+
+
+tests
+
+
+
+
+
+Node2
+
+
+std::endl
+
+
+
+
+
+Node1->Node2
+
+
+
+
+
+
+
+
+Node3
+
+
+math::is_prime
+
+
+
+
+
+Node1->Node3
+
+
+
+
+
+
+
+
diff --git a/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
index 164323fd3..babca0ba0 100644
--- a/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
+++ b/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map
@@ -1,7 +1,9 @@
diff --git a/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
index 01c938ff2..830cc3234 100644
--- a/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
+++ b/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5
@@ -1 +1 @@
-045fac8f0573f6c028be62240e1f7e2f
\ No newline at end of file
+ecc3356383182ba366fc14e7f9dd3ffe
\ No newline at end of file
diff --git a/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
index d5f9c8578..a10e972f3 100644
--- a/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
+++ b/db/d93/check__prime_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg
@@ -4,8 +4,8 @@
-
+