L6 (Primality) Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What’s fermat’s little theorem?

A

if an integer p is prime, then for every integer a:

a^(p-1) ≡ 1 (mod p)

note: not if and only if

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Propose an algorithm for testing if an input number N is NOT a prime

A
  1. pick some a in {2, … , N-1}
  2. if a^(N-1) ≡ 1 (mod N), then N could be a prime
  3. otherwise, it is NOT a prime
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

We want to test if N is prime. Suppose we pick a in {2, … , N}, and then we see that a^(N-1) ≡ 1 (mod N)

If this is the first time we do this, then what is the probability that N is prime?

A

0.5

if a^(N-1) ≡ 1 (mod N), then it has a 50% chance of being prime or not prime

This is the primality2() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Suppose we run the primality2(N) function k times for the same N. If it returns “True” in all k times, what is the probability that N is not a Prime

primality2(N) function:
Input is N, we pick a in {2, … , N}. Return “true” if a^(N-1) ≡ 1 (mod N) and “false” otherwise

A

(1/2)^k

For each time that we run primality2(N), there is a 1/2 chance that it is not prime. If we run it k times, then we simply raise the 1/2 to the power of k to get a (1/2)^k probability of N not being prime

The point of this is so that we can run it many times to test if a number is prime with a VERY low error rate

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What’s Lagrange’s prime number theorem for π(x) as the number of primes between 1 and x?

A

If π(x) is the number of primes between 1 and x, then:

π(x) ≈ x / ln(x)

This becomes more and more accurate as x goes to infinity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write an algorithm to generate a random prime number using primality2

What would the runtime of this algorithm be?

A

The runtime would be O(n) where n is the number of bits in N, which is roof(log(N))

so O(log(N))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly