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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.