1
$\begingroup$

I have to admit that I am totally noob to mathematica, and I have a question for which I have not found any easy-to-understand answer about.

How could I calculate the number of prime numbers of a certain form (like, for example, $4n+1$ or $4p+1$ being $p$ prime) lower than a given input $N$? Would there be any way to plot it respect to that $N$?

Thank you!

$\endgroup$
4
$\begingroup$

Number of primes

n = 10000;
primes = Prime[Range[PrimePi[n]]];

(* 4n + 1 *)
pickQ = Divisible[primes - 1, 4];
Length@ Pick[primes, pickQ]

(* 4p + 1 with p prime *)
pickQ2 = PrimeQ[(primes - 1) / 4];
Length@ Pick[primes, pickQ2]

Plots

(* 4n + 1 *)
nbprimes[n_] := With[{primes = Prime[Range[PrimePi[n]]]},
    Length@ Pick[primes, Divisible[primes - 1, 4]]
];

DiscretePlot[nbprimes[n], {n, 1, 100}]

enter image description here

(* 4p + 1 with p prime *)
nbprimes2[n_] := With[{primes = Prime[Range[PrimePi[n]]]},
    Length@ Pick[primes, PrimeQ[(primes - 1)/4]]
];

DiscretePlot[nbprimes2[n], {n, 1, 100}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.