0
$\begingroup$

Write a function f[n] that returns prime numbers contained between n and 2n. It's a variation of Chebyshev's inequality. Please, help.

$\endgroup$
2
  • 2
    $\begingroup$ Do you know about Prime[] and PrimePi[]? $\endgroup$ Oct 14, 2018 at 8:54
  • $\begingroup$ Is this a homework problem? If so, it should tagged as such. $\endgroup$
    – m_goldberg
    Oct 14, 2018 at 12:16

2 Answers 2

2
$\begingroup$
n = 100;
Select[Prime[Range@@PrimePi[{n,2n}]],#>=n&]

returns

{101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199}
$\endgroup$
1
$\begingroup$
n = 100;
Prime[Range @@ ({1 - Boole[PrimeQ[n]], 0} + PrimePi[{n, 2 n}])]

{101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199}

$\endgroup$
1

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.