Problem 52584. Easy Sequences 9: Faithful Pairs

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

62.96% Correct | 37.04% Incorrect
Last Solution submitted on Mar 31, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers16

Suggested Problems

More from this Author116

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!