Skip to content

algocpp::math::isprime

sakamotor edited this page Jul 17, 2023 · 1 revision

algocpp::math::isprime

Description

Function for fast determination of prime numbers

This program is by @asksaito of Qiita. Thank you!

Time

$O(1)$ if $N$ is even or less than $2$

Otherwise, $O(\sqrt N)$

Example

#include <iostream>
#include <algocpp/math.hpp>
using namespace std;

int main()
{
    cout << boolalpha;

    // false
    cout << algocpp::math::isprime(15) << endl;

    // true
    cout << algocpp::math::isprime(17) << endl;
}
Clone this wiki locally