both inner and outer loops are checking only within possible limits. the even numbers are not checked even once throughout the process. Checkout the results for different N values in the end. ![]() My code takes significantly lesser iteration to finish the job. Mersenne primes and perfect numbers are two deeply interlinked types of natural numbers in number theory.Mersenne primes, named after the friar Marin Mersenne, are prime numbers that can be expressed as 2 p 1 for some positive integer p.For example, 3 is a Mersenne prime as it is a prime number and is expressible as 2 2 1. Using Sieve of Eratosthenes logic, I am able to achieve the same results with much faster speed. How would I need to change this code to the way my book wants it to be? int main () So I did try changing my 2nd loop to for (int j=2 j ![]() It mentions something about square root of a number. What is the total number of prime numbers up to 100 There are 25 prime numbers between 1 and 100. ![]() This c++ code prints out the following prime numbers: 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97.Ä«ut I don't think that's the way my book wants it to be written. There are 25 prime numbers between 1 and 100.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |