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 Solvers20
Suggested Problems
-
Given two arrays, find the maximum overlap
1792 Solvers
-
10783 Solvers
-
Make an awesome ramp for a tiny motorcycle stuntman
764 Solvers
-
How long is the longest prime diagonal?
412 Solvers
-
find nth even fibonacci number
99 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!