0

Consider the following naive monte Carlo algorithn for primality testing of a number n.

isPrimeMonteCarlo(n,t){
/*
 * Take an integer n as input and check wheather it is prime or not
 * using the naive monte carlo method.
 * If the number is prime return True else return False.
 * */
if(n<=1)
    return False
m = sqrt(n);
for i = 1 to t:
    j = random()%m+2
    if n%j==0:
        return False
return True
}

Find the value of t such that the algorithm produces the correct output with high probability?

What i could come up with so far:

Assume n is non prime, the algorithm will fail when it outputs that n is prime.This happens when no number j gives n%j==0. j is chosen from [2,sqrt(n)+2]. We want j such that j does not divide n in any of the t iterations.

Any such j must be a divisor of n. The problem reduces to finding the number of divisors of n such that they are <= sqrt(n)+2. I am not able to find a bound on this number. Any help would be appreciated.

Milan
  • 403
  • 2
  • 8
  • 1
    Please use a spelling checker; correct the title, too. – greybeard Feb 15 '17 at 09:36
  • The question you seem to be asking might be better on a maths forum without the code. I tried looking around from http://math.stackexchange.com/questions/1053062/upper-limit-for-the-divisor-function but that's not quite the same question; https://terrytao.wordpress.com/2008/09/23/the-divisor-bound/ has other bounds for it – Pete Kirkham Feb 15 '17 at 10:02
  • IIRC, half of the divisors of N should be < sqrt(N). – RBarryYoung Feb 15 '17 at 20:41
  • The total number of divisors is determined by the tau(n) function. unfortunately, the only practical way I know of to determine it is to factor N. – RBarryYoung Feb 15 '17 at 20:45

0 Answers0