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

Using c++ (a) Write a method that takes as input a natural number n and determin

ID: 3828531 • Letter: U

Question

Using c++

(a) Write a method that takes as input a natural number n and determines if n is a prime number.

(b) Consider the sequence of prime numbers 2, 3, 5, 7, 11, 13, 17, … . Let pi denote the i-th number in the sequence, i.e, p1 = 2, p2 = 3, p3 = 5, p4 = 7, p5 = 11 … . For i > 0, let Ni = p1 p2 . . . pi + 1. Professor Paul Erdös claims that for all i > 0, Ni is a prime number. Prove that Professor Erdös is wrong. Write a computer program that produces the smallest counter-example for Professor Erdös’ claim.MATH178 Discrete Mathematics

(a) Write a method that takes as input a natural number n and determines if n is a prime number.

(b) Consider the sequence of prime numbers 2, 3, 5, 7, 11, 13, 17, … . Let pi denote the i-th number in the sequence, i.e, p1 = 2, p2 = 3, p3 = 5, p4 = 7, p5 = 11 … . For i > 0, let Ni = p1 p2 . . . pi + 1. Professor Paul Erdös claims that for all i > 0, Ni is a prime number. Prove that Professor Erdös is wrong. Write a computer program that produces the smallest counter-example for Professor Erdös’ claim.

Explanation / Answer

a)

bool isPrime(int n){

   if(n <= 1)
       return false;

   for(int i=0; i<=n/2; i++){
       if(n%i == 0)
           return false;
   }

   return true; // n is prime, not divisible except n and 1
}

b)

Lets n = 2

So, p1 = 2, p2 = 3, p3 = 5

N3 = 30

And 30 is not a prime number

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote