Implementazioni di algoritmi/Test deterministico
bool deterministic_test (unsigned long int x) {
int a = 2 ;
int b = (x/2) + 1 ;
if (x == 2 or x == 3 or x == 5 or x == 7) {
return true ; }
else {
while (a <= b) {
if (x % a == 0) {
return false ; break ; } ;
if (a == b) {
if (x % a != 0) {return true ; break ; } ; } ;
a++ ; } ; } ; } ;
def primo(num):
if num in [2, 3]: return True
d=2
q, r = divmod(num, d)
if r==0: return False
d=3
q, r = divmod(num, d)
if r==0: return False
if r==1: i=2
else: i=4
d=5
incdiv=4
q, r = divmod(num, d)
while d<=q:
if r==0: return False
incdiv=6-incdiv
d+=incdiv
q, r = divmod(num, d)
return True