find prime number c++
#include <math.h>
// time: O(sqrt(n)) .. space: O(1)
bool isPrime(int n) {
if (n < 2) return false;
int iter = 2;
while(iter <= sqrt(n)) {
if (n % iter == 0) return false;
iter++;
}
return true;
}
find prime number c++
#include <math.h>
// time: O(sqrt(n)) .. space: O(1)
bool isPrime(int n) {
if (n < 2) return false;
int iter = 2;
while(iter <= sqrt(n)) {
if (n % iter == 0) return false;
iter++;
}
return true;
}
prime number c++
template<class T> bool isPrime(T n)
{
T i;
if(i<2) return false;
for(i = 2; i * i <= n; i++) {
if(n % i == 0) return false;
}
return true;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us