Answered step by step
Verified Expert Solution
Link Copied!

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:

image text in transcribed

image text in transcribed

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-M74207281

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Spatial And Temporal Databases 8th International Symposium Sstd 2003 Santorini Island Greece July 2003 Proceedings Lncs 2750

Authors: Thanasis Hadzilacos ,Yannis Manolopoulos ,John F. Roddick ,Yannis Theodoridis

2003rd Edition

3540405356, 978-3540405351

More Books

Students also viewed these Databases questions

Question

Give an IJVM translation for the following statement: m = n + n

Answered: 1 week ago