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 Solvers19
Suggested Problems
-
Find all elements less than 0 or greater than 10 and replace them with NaN
15782 Solvers
-
1881 Solvers
-
Extract Built In Functions and Toolbox Functions from String or Function Handle
82 Solvers
-
193 Solvers
-
Numbers spiral diagonals (Part 2)
196 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!