Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C code: Problem 3 (20 points): Write a program that finds all prime numbers from 1 to 1,000,000. Your program should call a user-defined
In C code:
Problem 3 (20 points): Write a program that finds all prime numbers from 1 to 1,000,000. Your program should call a user-defined function called "primes" that returns PASS (i.e., 1) if a number is prime and FAIL (i.e., 0), otherwise. The function prototype should be as follows: int prime(int p); A prime number (or a prime) is a natural number that has exactly two distinct divisors: 1 and itself. For primality testing use the following algorithm. Algorithm: Let n be the number tested for primality. If n is not divisible by any number m smaller than [Vn] then n is a prime. Else n is not a prime Example: 13 is a prime because no number less than 4 divides it The rationale behind this simple algorithm is the fact if a number n can be factored (analyzed to factors other than 1 and itself), at least one of the factors has to be less or equal to its square root Vn. This is easily shown via contradiction. If n could be analyzed to two factors a > Vn and b > Vn, then ab > n. Hence, at least one factor has to be less or equal to Vn. Prime numbers used for cryptographic applications are typically very large (in the order of thousand bits long). Details on the longest known prime can be found here: https://www.mersenne.org/primes/?press-M74207281Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started