Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I NEED MATLAB CODE TO SOLVE IT Two prime numbers are said to be sequential if th

ID: 3013109 • Letter: I

Question

I NEED MATLAB CODE TO SOLVE IT Two prime numbers are said to be sequential if there are no intermediate primes. For example, 13 and 17 are sequential primes, but 13 and 19 are not. The prime gap between two sequential primes p < q is q p. For example, the prime gap between 13 and 17 is 4. Sequential primes are said to be twins when their prime gap is 2. For example, 3 and 5 are twins, 5 and 7 are twins, and 7 and 11 are not twins. Hint: >> help primes and >> help diff and >> help find . (a) Find the largest twin primes less than 10000. (b) Find the smallest twin primes greater than 30000. (c) Find the smallest sequential primes with prime gap 100 I NEED MATLAB CODE TO SOLVE IT Two prime numbers are said to be sequential if there are no intermediate primes. For example, 13 and 17 are sequential primes, but 13 and 19 are not. The prime gap between two sequential primes p < q is q p. For example, the prime gap between 13 and 17 is 4. Sequential primes are said to be twins when their prime gap is 2. For example, 3 and 5 are twins, 5 and 7 are twins, and 7 and 11 are not twins. Hint: >> help primes and >> help diff and >> help find . (a) Find the largest twin primes less than 10000. (b) Find the smallest twin primes greater than 30000. (c) Find the smallest sequential primes with prime gap 100 I NEED MATLAB CODE TO SOLVE IT Two prime numbers are said to be sequential if there are no intermediate primes. For example, 13 and 17 are sequential primes, but 13 and 19 are not. The prime gap between two sequential primes p < q is q p. For example, the prime gap between 13 and 17 is 4. Sequential primes are said to be twins when their prime gap is 2. For example, 3 and 5 are twins, 5 and 7 are twins, and 7 and 11 are not twins. Hint: >> help primes and >> help diff and >> help find . (a) Find the largest twin primes less than 10000. (b) Find the smallest twin primes greater than 30000. (c) Find the smallest sequential primes with prime gap 100

Explanation / Answer

(a) to find largest twin primes less than 10000, we can put following code in MATLAB:

a = primes(10000);

a = a( a > 0 );

n = find( diff( [ a(1: end-1) ; a(2 : end) ] ) ==2 );

out = a( [ n, n+1] ).

Then from the list that is displayed in output select the largest.

(b) to find smallest twin primes greater than 30000:

a = primes(40000);

a = a(a > 30000);

n = find( diff( [ a(1: end-1) ; a(2 : end) ]) ==2 );

out = a( n, n+1 ).

Then from the list displayed in output select the smallest.

(c) Do same as above.