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

35.29% Correct | 64.71% Incorrect
Last Solution submitted on Sep 02, 2025

Problem Comments

Solution Comments

Show comments
AI Is Transforming Engineering Workflows
It’s an honor to deliver the keynote at MATLAB EXPO 2025. I'll...
0
MATLAB EXPO 2025 Registration is Now Open! November 12 – 13, 2025
Registration is now open for MathWorks annual virtual event MATLAB EXPO 2025...
0

Problem Recent Solvers4

Suggested Problems

More from this Author116

Community Treasure Hunt

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

Start Hunting!