A "faithful number" is a non-prime number that is one less or one more than some prime number but not both. For example, for numbers up to 20, the numbers 1 8, 10, 14, 16 and 20 are faithful. The number 4 does not qualify because it is equal to "3 + 1" and "5 - 1".
If both 'x' and 'x+2' are faithful but not to the same prime, the pair (x, x+2) is called a faithful pair. So, from 1 to 20 the faithful pairs are (8, 10) and (14, 16). Faithful pairs are scarse and rarer than primes themselves. We can only find 1 faithful pair for numbers 1 to 10, 5 pairs for numbers up to 50 and 8 pairs up to 100.
Let "P" be the set of all faithful pairs from 1 to a given number "n". We define "F" as the set of all p1, p1 < p2 ∀pairs (p1,p2) ∈ P. Write a function "S(n)", that sums all the elements of F.
For 1 to 20, P(20) = [8 10; 14 16], F(20) = [8 14] and S(20) = 22.
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers22
Suggested Problems
-
Sort a list of complex numbers based on far they are from the origin.
5820 Solvers
-
252 Solvers
-
Given a window, how many subsets of a vector sum positive
873 Solvers
-
Lychrel Number Test (Inspired by Project Euler Problem 55)
116 Solvers
-
Find the sides of an isosceles triangle when given its area and height from its base to apex
2240 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!