Questions tagged [primes]

125 questions
112
votes
7 answers

Why is it best to use a prime number as a mod in a hashing function?

If I have a list of key values from 1 to 100 and I want to organize them in an array of 11 buckets, I've been taught to form a mod function $$ H = k \bmod \ 11$$ Now all the values will be placed one after another in 9 rows. For example, in the…
CodyBugstein
  • 3,017
  • 11
  • 31
  • 46
31
votes
3 answers

When is the AKS primality test actually faster than other tests?

I am trying to get an idea of how the AKS primality test should be interpreted as I learn about it, e.g. a corollary for proving that PRIMES ⊆ P, or an actually practical algorithm for primality testing on computers. The test has polynomial runtime…
Vortico
  • 411
  • 1
  • 4
  • 5
23
votes
5 answers

Data compression using prime numbers

I have recently stumbled upon the following interesting article which claims to efficiently compress random data sets by always more than 50%, regardless of the type and format of the data. Basically it uses prime numbers to uniquely construct a…
Klangen
  • 1,100
  • 8
  • 15
17
votes
2 answers

Why is factoring large integers considered difficult?

I read somewhere that the most efficient algorithm found can compute the factors in $O(\exp((64/9 \cdot b)^{1/3} \cdot (\log b)^{2/3})$ time, but the code I wrote is $O(n)$ or possibly $O(n \log n)$ depending on how fast division and modulus are.…
14
votes
1 answer

Is determining if there is a prime in an interval known to be in P or NP-complete?

I saw from this post on stackoverflow that there are some relatively fast algorithms for sieving an interval of numbers to see if there is a prime in that interval. However, does this mean that the overall decision problem of: (Does there exists a…
Ari
  • 1,661
  • 10
  • 23
13
votes
3 answers

Complexity-theoretic difficulty of checking the value of $\pi(x)$?

The prime-counting function, demoted $\pi(x)$, is defined as the number of prime numbers less than or equal to $x$. We can define a decision problem from $\pi(x)$ as follows: Given two numbers $x$ and $n$, written in binary, decide if $\pi(x) =…
templatetypedef
  • 9,302
  • 1
  • 32
  • 62
13
votes
8 answers

Can any known sub-Turing-complete model of computation enumerate precisely the set of prime numbers?

I wish there were more, but the subject pretty much captures my whole question. Is there a non-Turing-complete model (some constrained term rewriting system or automaton or what have you) which is known to be able to enumerate the prime numbers, all…
Trev
  • 316
  • 2
  • 10
10
votes
1 answer

What is the average-case complexity of trial division?

The trial division algorithm for checking if a number $N$ is prime works by trying to divide $N$ by all integers in the range 2, 3, ..., $\lfloor \sqrt{n} \rfloor$. If any of them cleanly divide $N$, then we say that $N$ is composite; otherwise we…
10
votes
3 answers

Why Miller–Rabin instead of Fermat primality test?

From the proof of Miller-Rabin, if a number passes the Fermat primality test, it must also pass the Miller-Rabin test with the same base $a$ (a variable in the proof). And the computation complexity is the same. The following is from the Fermat…
ZijingWu
  • 201
  • 2
  • 3
9
votes
3 answers

Algorithm for checking if a list of integers is pairwise coprime

Are thre any efficient algorithms for checking if a list of integers is pairwise coprime, or would a more general algorithm be the best option available?
user2782067
  • 193
  • 1
  • 5
9
votes
2 answers

Efficiently computing the smallest integer with n divisors

In order to tackle this problem I first observed that $$\phi(p_1^{e_1} \space p_2^{e_2} \cdots \space p_k^{e_k}) = (e_1 + 1)(e_2 + 1)\cdots(e_k +1)$$ Where $\phi(m)$ is the number of (not necessarily prime) divisors of $m$. If $m$ is the smallest…
orlp
  • 13,988
  • 1
  • 26
  • 41
8
votes
3 answers

More details about the Baillie–PSW test

It's clear that Mathematica uses the Baillie–PSW test for its PrimeQ function (which tests primality), and as I read in the Mathematica documentation, it starts with trial division, then base 2 and 3 Miller–Rabin, and then Lucas pseudoprime test. My…
Ramez Hindi
  • 247
  • 1
  • 3
7
votes
2 answers

What is the time complexity of checking if a number is prime?

Could some one please explain how to get the time complexity of checking if a number is prime? I'm really confused as to if it is $O(\sqrt{n})$ or $O(n^2)$. I iterate from $i=2$ to $\sqrt{n}$ and continuously checking if n%i != 0. However, do we…
TdBm
  • 213
  • 2
  • 7
6
votes
3 answers

Complexity of finding factors of a number

I have come up with two simple methods for finding all the factors of a number $n$. The first is trial division: For every integer up to $\sqrt{n}$, try to divide by $d$, and if the remainder is $0$ then add $d$ and $n/d$ to the factor list.…
qwr
  • 628
  • 1
  • 7
  • 22
6
votes
2 answers

What is the name of this prime number algorithm?

Does the following recursive algorithm have a name? If so, what is it? procedure main(): myFilter = new Filter( myPrime = 2 ) //first prime number print 2 //since it would not otherwise be printed for each n in 3 to MAX: if…
Sukotto
  • 163
  • 5
1
2 3
8 9