Questions tagged [prime-numbers]

Questions on testing and computing prime numbers.

Useful Links:

185 questions
11
votes
5 answers

Finding large primes

I'm quite new to Mathematica and I am trying to find large prime numbers that can be written using only the digits 0, 1, 2 and 3 and more than half of these digits have to be 0. For example 1000 and 20001 would qualify. I was thinking of using the…
aL_eX
  • 257
  • 2
  • 7
5
votes
6 answers

How to combine a list of the prime factors?

As a simple example, there is a list of prime factors. {{2, 1}, {3, 2}, {43, 5}, {26684839, 1}} How to combine them to the number 70612139395722186 using Mathematica?
Klaas
  • 55
  • 3
5
votes
1 answer

PrimeQ versus Baillie-PSW primality test

I read here that Baillie-PSW primality test is proven correct up to $2^{64}$, but I understand PrimeQ is only proven correct up to $10^{16}$, or was that extended up to $2^{64}$? Doesn't PrimeQ use a variation of Baillie-PSW? For many years I have…
Ted Ersek
  • 7,124
  • 19
  • 41
5
votes
0 answers

The inverse function of "Prime"

Consider p such that PrimeQ[p] == True. How do I compute n such that Prime[n] == p? In other words, what is the inverse function of "Prime"? EDIT: As a concrete example, consider p to be the first prime that factorizes rsa-768, p = rsa768a =…
Jorge Leitao
  • 813
  • 6
  • 17
3
votes
2 answers

Prime power list

Update Is there any better way of generating the nth prime power? Chip Hurst gave a great solution for a list below, so PrimePowersUpTo[x_] := Union @@ Table[Prime[Range[PrimePi[x^(1/n)]]]^n, {n, Log2[x]}] pp=PrimePowersUpTo[10^7]; pp[[n]] would…
martin
  • 8,678
  • 4
  • 23
  • 70
3
votes
3 answers

Prime $p$ that results in a power of 2

For every prime number $p$, the function ${\rm ms_2}(p)$ gives the smallest prime number that results in a power of 2 when added to $p$. For example: ${\rm ms_2}(857) = 167$, since $857+167 = 1024 = 2^{10}$. What is wrong with this Mathematica…
2
votes
0 answers

Optimizing getting a large number of values from PrimePi

I found out yesterday that there is a conjecture that the following function generates an addition chain: $f(n)=\pi({n(n+1)\over 2}+1)$ for and integer $n\ge 1$. $\pi(x)$ is the prime counting function. So the addition chain part requires: $f(x) …
Neill Clift
  • 153
  • 6
2
votes
0 answers

Faster Prime[n] for large n, and for n larger than 10^12

Is there a faster implementation of Prime[] available somewhere, already implemented by someone? (Maybe as a compiled routine?) The default function in Mathematica is slow for large values, and does not work for very large values (greater than…
Vepir
  • 622
  • 3
  • 11
2
votes
2 answers

A Wilson prime is a prime p such that (p−1)!≡−1 mod p^2. Write a procedure which determines all Wilson primes less than10^4

I try to use the for loop to solve this question, but it does not work. And here is what I did. For[p = 2,p<=10000,(p-1)! = -1 mod (p^2),Print[p]] I am not sure how to describe "(p−1)!≡−1 mod p^2" in Mathematica. Could you give me some suggestions?…
User796
  • 47
  • 5
2
votes
2 answers

Checking whether a certain number is prime

Using the primality test on this site, I found that the concatenation of the digit reversal of the first 548 odd primes in the reverse order is a prime!. It is only a 1998-digit prime, but it took more than an hour for the site's calculator to state…
Toni S
  • 33
  • 3
2
votes
2 answers

Asymptotic density of twin primes gives wrong result in Mathematica

One can compute the amount of twin primes below a positive integer $n$ by using the Mathematica command (taken from OEIS A001097): Length[Select[Prime[Range[n]], PrimeQ[# + 2] &]] The twin prime conjecture states that this value should approach…
Klangen
  • 1,009
  • 5
  • 14
2
votes
1 answer

Showing the difference between Primes

I create a list of primes in table form... How do I generate and display the difference between the prime numbers in sequence? In[1]:= Table[Prime[n], {n, 10}] Out[1]= {2, 3, 5, 7, 11, 13, 17, 19, 23, 29} expected output: {1, 2, 2, 4, 2, 4, 2, 4,…
Technophobe01
  • 215
  • 1
  • 6
1
vote
1 answer

Consecutive integers that can be written as the product of three distinct primes

Mathematica novice here. I want to start with a list of integers that are the product of three distinct primes m,n, and o, where 2 <= m|n|o < 2000. Sort[Times @@@ Subsets[Select[Range[2000], PrimeQ], {3}]] How do I find the longest subsequence…
pgblu
  • 249
  • 1
  • 9
1
vote
0 answers

How can I check whether a 10k digit integer is a probable prime?

I would like to detect prime numbers within an interval $\mathcal{I}:[a,b]$. The only problem is that the interval contains very large numbers - in excess of 10000 digits each and $\# \mathcal{I}$ is also very large. One of my tasks involves…
Klangen
  • 1,009
  • 5
  • 14
1
vote
2 answers

Number of primes p less than or equal to X satisfying a congruence relation

I'm looking for a code that finds the number of primes p less than or equal to X satisfying p is congruent to 1 (mod 4) and another code that finds the number of primes p less than or equal to X satisfying p is congruent to 3 (mod 4).
Karam
  • 197
  • 5
1
2