The prime Pi function is defined as the number of prime numbers from 1 to a certain given limit. In MATLAB, it is easy to create a prime Pi procedure, because there are built-in functions such as "primes" and "isprime". To calculate the prime Pi up to 100, we may just proceed as follows:
>> numel(primes(100))
>> ans =
25
>> nnz(isprime(1:100))
>> ans =
25
Can we make a function for "composite Pi", which is the number of composite numbers from 1 to a given limit, inclusive? Let's find out...
NOTE: The number '1' is considered as neither prime nor composite.
Solution Stats
Problem Comments
3 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers6
Suggested Problems
-
Remove the small words from a list of words.
1560 Solvers
-
Lychrel Number Test (Inspired by Project Euler Problem 55)
111 Solvers
-
Return fibonacci sequence do not use loop and condition
854 Solvers
-
660 Solvers
-
Easy Sequences 16: Volume of Embedded Octahedron
10 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
I mean...doing this above 1e10 won't be easy anyway, no matter prime or composite.
Lincoln Poon,
Yes, they're really the same problem, as (designating the composite counting function as κ(n)), κ(n) + ?(n) + 1 = n. There are techniques to do the count without creating an array for x>√n, and even for x>∛n.
If anyone does find a way to solve this precisely without some hack, please, publish a scientific paper, and do not post your code here. This problem is not made from an easy sequence at all.