find the sum and the different of first and the last prime or composite?
Answers
Answered by
1
Approach: The sum of two prime numbers is always even which is composite as they are odd numbers except 2. There are two cases now,
When N is even then we can print any N prime numbers except 2 and their sum will always be even i.e. odd numbers when added even number of times will give an even sum.
When N is odd then we can print 2 and any other N – 1 primes to make sure that the sum is even. Since, N – 1 is even so the sum will be even for any primes except 2 then we add 2 as the Nth number to make sure that the sum remains even.
MARK ME AS BRAINLIEST
Similar questions