Luzhiled's Library

This documentation is automatically generated by online-judge-tools/verification-helper

View the Project on GitHub ei1333/library

:heavy_check_mark: Is Prime(素数判定)
(math/number-theory/is-prime.hpp)

is_prime

bool is_prime(int64_t x)

$x$ が素数なら true、素数でなければ false を返します。

制約

計算量

Verified with

Code

bool is_prime(int64_t x) {
  for(int64_t i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
#line 1 "math/number-theory/is-prime.hpp"
bool is_prime(int64_t x) {
  for(int64_t i = 2; i * i <= x; i++) {
    if(x % i == 0) return false;
  }
  return true;
}
Back to top page