Determine all pairs of prime numbers p and q less than 100, such that the following five numbers:
p+6, p+10, q+4, q+10, p+q+1
are all prime numbers.
pr=primes(100);
for pno=1:length(pr)
for qno=1:length(pr)
p=pr(pno);
q=pr(qno);
if isprime(p+6) && isprime(p+10)
if isprime(q+4) && isprime(q+10)
if isprime(p+q+1)
disp([p q])
end
end
end
end
end
p q
7 3
13 3
37 3
97 3
A brute force program can be more objective, avoiding the assumption that all numbers involved need be under 100--only p and q themselves need to be.
|
Posted by Charlie
on 2024-07-01 13:47:53 |