Pergunta de entrevista da empresa Box

Write a function that gets a integer and returns true if the integer is prime

Respostas da entrevista

Sigiloso

11 de fev. de 2013

Fermat's little theorem states: if p is prime, then for every 1 <= a p, a^{p-1} = 1 (mod p) So pick a random positive integer a < P, and if it passes Fermat's little theorem, then it's prime and if it doesn't, then it's likely still prime (with very few exceptions... Eg: Carmichael numbers, but Carmichael numbers are EXTREMELY rare, where you can probably just have a small list of them)

1

Sigiloso

11 de fev. de 2013

Shoot... typo^ "So pick a random positive integer a < P, and if it fails Fermat's little theorem, then it's composite and if it doesn't, then it's likely prime"