Easy Sequences 7: Easy as Composite Pi - MATLAB Cody - MATLAB Central

Problem 52567. Easy Sequences 7: Easy as Composite Pi

Difficulty:Rate
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

37.5% Correct | 62.5% Incorrect
Last Solution submitted on Nov 23, 2022

Problem Comments

Solution Comments

Show comments

Group

Easy Sequences Volume I Image
Easy Sequences Volume I
  • 10 Problems
  • 8 Finishers

Problem Recent Solvers4

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page