Problem 44861. Ratio between sums of prime and non-prime numbers
Write a function that calculates the ratio between the sum of the prime numbers less than or equal to x, and the sum of the non-prime numbers up to the greatest prime less than or equal to x.
For example, if x = 7, then:
sum_prime = sum([2 3 5 7]) = 17
sum_non_prime = sum([1 4 6]) = 11
Therefore, the desired ratio is:
prime_ratio = sum_prime / sum_non_prime = 17 / 11
Solution Stats
Problem Comments
-
3 Comments
Gergely Patay
on 28 Jun 2019
test case #2 is not correct.
Rafael S.T. Vieira
on 27 Aug 2020
The problem description should be change to "and the sum of non-prime numbers up to the greatest prime lower than x".
goc3
on 29 Sep 2020
Thank you for that clarification, @Rafael S.T. Vieira. The problem title and description have been improved, along with added test cases.
Solution Comments
Show commentsProblem Recent Solvers36
Suggested Problems
-
386 Solvers
-
find whether it is prime or not
146 Solvers
-
107 Solvers
-
360 Solvers
-
191 Solvers
More from this Author11
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!