How to do this in maple?

241 Views Asked by At

1.Sexy primes are prime numbers that differ from each other by six. For example, the first 5 sexy prime pairs are (5, 11), (7, 13), (11, 17), (13, 19), (17, 23). Find the number of sexy prime pairs (p, p + 6) such that p ≤ 201415.

2.For each positive number n, define S(n) to be the sum of all its digits. For example, S(2014) = 2 + 0 + 1 + 4 = 7. Find S(2014^{2014}).

1

There are 1 best solutions below

4
On

There are no mathematical tricks involved. This is pure brute-force but entirely straightforward Maple coding. The coding is easy in each case and executes in seconds or less.

Problem 1: Your solution technique is way off. In Maple,

n:= 0:
p:= 2:
while p <= 201415 do
     if isprime(p+6) then n:= n+1 end if;
     p:= nextprime(p)
end do:
n;

The returned answer is 4317.

Problem 2: Don't let numbers with thousands of digits scare you. Maple handles them in an instant. This one is a one-liner:

`+`(convert(2014^2014, base, 10)[]);

The returned answer is 29761.