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
-
Number of 1s in a binary string
10989 Solvers
-
Generate a vector like 1,2,2,3,3,3,4,4,4,4
13640 Solvers
-
350 Solvers
-
182 Solvers
-
Large Sum (inspired by Project Euler 13)
114 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!