mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-02-04 02:56:40 +08:00
Revert "feat: update CMake version to 3.26.4 (#2486)"
This reverts commit 2d492834b1.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.26.4)
|
cmake_minimum_required(VERSION 3.9)
|
||||||
project(Algorithms_in_C++
|
project(Algorithms_in_C++
|
||||||
LANGUAGES CXX
|
LANGUAGES CXX
|
||||||
VERSION 1.0.0
|
VERSION 1.0.0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief A simple program to check if the given number is a
|
* @brief A simple program to check if the given number is a [factorial](https://en.wikipedia.org/wiki/Factorial) of some
|
||||||
* [factorial](https://en.wikipedia.org/wiki/Factorial) of some number or not.
|
* number or not.
|
||||||
*
|
*
|
||||||
* @details A factorial number is the sum of k! where any value of k is a
|
* @details A factorial number is the sum of k! where any value of k is a
|
||||||
* positive integer. https://www.mathsisfun.com/numbers/factorial.html
|
* positive integer. https://www.mathsisfun.com/numbers/factorial.html
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief
|
* @brief
|
||||||
* A simple program to check if the given number is
|
* A simple program to check if the given number is [Prime](https://en.wikipedia.org/wiki/Primality_test) or not.
|
||||||
* [Prime](https://en.wikipedia.org/wiki/Primality_test) or not.
|
|
||||||
* @details
|
* @details
|
||||||
* A prime number is any number that can be divided only by itself and 1. It
|
* A prime number is any number that can be divided only by itself and 1. It must
|
||||||
* must be positive and a whole number, therefore any prime number is part of
|
* be positive and a whole number, therefore any prime number is part of the
|
||||||
* the set of natural numbers. The majority of prime numbers are even numbers,
|
* set of natural numbers. The majority of prime numbers are even numbers, with
|
||||||
* with the exception of 2. This algorithm finds prime numbers using this
|
* the exception of 2. This algorithm finds prime numbers using this information.
|
||||||
* information. additional ways to solve the prime check problem:
|
* additional ways to solve the prime check problem:
|
||||||
* https://cp-algorithms.com/algebra/primality_tests.html#practice-problems
|
* https://cp-algorithms.com/algebra/primality_tests.html#practice-problems
|
||||||
* @author [Omkar Langhe](https://github.com/omkarlanghe)
|
* @author [Omkar Langhe](https://github.com/omkarlanghe)
|
||||||
* @author [ewd00010](https://github.com/ewd00010)
|
* @author [ewd00010](https://github.com/ewd00010)
|
||||||
@@ -22,37 +21,37 @@
|
|||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
namespace math {
|
namespace math {
|
||||||
/**
|
/**
|
||||||
* @brief Function to check if the given number is prime or not.
|
* @brief Function to check if the given number is prime or not.
|
||||||
* @param num number to be checked.
|
* @param num number to be checked.
|
||||||
* @return true if number is a prime
|
* @return true if number is a prime
|
||||||
* @return false if number is not a prime.
|
* @return false if number is not a prime.
|
||||||
*/
|
|
||||||
bool is_prime(int64_t num) {
|
|
||||||
/*!
|
|
||||||
* Reduce all possibilities of a number which cannot be prime with the first
|
|
||||||
* 3 if, else if conditionals. Example: Since no even number, except 2 can
|
|
||||||
* be a prime number and the next prime we find after our checks is 5,
|
|
||||||
* we will start the for loop with i = 5. then for each loop we increment
|
|
||||||
* i by +6 and check if i or i+2 is a factor of the number; if it's a factor
|
|
||||||
* then we will return false. otherwise, true will be returned after the
|
|
||||||
* loop terminates at the terminating condition which is i*i <= num
|
|
||||||
*/
|
*/
|
||||||
if (num <= 1) {
|
bool is_prime(int64_t num) {
|
||||||
return false;
|
/*!
|
||||||
} else if (num == 2 || num == 3) {
|
* Reduce all possibilities of a number which cannot be prime with the first
|
||||||
return true;
|
* 3 if, else if conditionals. Example: Since no even number, except 2 can
|
||||||
} else if (num % 2 == 0 || num % 3 == 0) {
|
* be a prime number and the next prime we find after our checks is 5,
|
||||||
return false;
|
* we will start the for loop with i = 5. then for each loop we increment
|
||||||
} else {
|
* i by +6 and check if i or i+2 is a factor of the number; if it's a factor
|
||||||
for (int64_t i = 5; i * i <= num; i = i + 6) {
|
* then we will return false. otherwise, true will be returned after the
|
||||||
if (num % i == 0 || num % (i + 2) == 0) {
|
* loop terminates at the terminating condition which is i*i <= num
|
||||||
return false;
|
*/
|
||||||
|
if (num <= 1) {
|
||||||
|
return false;
|
||||||
|
} else if (num == 2 || num == 3) {
|
||||||
|
return true;
|
||||||
|
} else if (num % 2 == 0 || num % 3 == 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
for (int64_t i = 5; i * i <= num; i = i + 6) {
|
||||||
|
if (num % i == 0 || num % (i + 2) == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} // namespace math
|
} // namespace math
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
/**
|
/**
|
||||||
* @file
|
* @file
|
||||||
* @brief
|
* @brief
|
||||||
* The
|
* The [Boyer–Moore](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm) algorithm searches for occurrences of pattern P in text T by
|
||||||
* [Boyer–Moore](https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string-search_algorithm)
|
* performing explicit character comparisons at different alignments. Instead of
|
||||||
* algorithm searches for occurrences of pattern P in text T by performing
|
* a brute-force search of all alignments (of which there are n - m + 1),
|
||||||
* explicit character comparisons at different alignments. Instead of a
|
|
||||||
* brute-force search of all alignments (of which there are n - m + 1),
|
|
||||||
* Boyer–Moore uses information gained by preprocessing P to skip as many
|
* Boyer–Moore uses information gained by preprocessing P to skip as many
|
||||||
* alignments as possible.
|
* alignments as possible.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user