Homework Solution: CSE2383 Programming Assignment 1, version 1.2 Page 1…

    CSE2383 Programming Assignment 1, version 1.2 Page 1 Algorithm Analysis Objective The objective of this programming assignment is to present the student with a C++ introduction assignment with a more challenging problem to solve than the basic practice tasks given in regular homework assignments. This assignment also attempts to illustrate the differences in running times for algorithms that perform the same task: finding prime numbers smaller than a given integer. Instructions Implement a program that asks the user for an integer n, which method (trial division or sieve of Eratosthenes) to use, and whether the prime numbers should be printed to the screen. The program should then find all of the prime numbers smaller than n using the selected method and print the time taken by the algorithm. There is a timer class and example program attached to this assignment. During testing of your program use the option to print the prime numbers found by the algorithms to the screen for verification. Finding prime values by Trial Division To decide if a number is prime using trial division, try dividing the number by all integers between 2 and the square root of the number. If there is a remainder from all of the division operations, the number is prime. You will test each integer less than n using this process to create a list of all the prime numbers less than n. Finding prime values by Sieve of Eratosthenes The following excerpt for finding prime numbers using the Sieve of Eratosthenes algorithm is from http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes (it is important that you view this page to get a better idea on what the algorithm does): To find all the prime numbers less than or equal to a given integer n by Eratosthenes' method: 1. Create a list of consecutive integers from 2 to n: (2, 3, 4, ..., n). 2. Initially, let p equal 2, the first prime number. 3. Starting from p, count up in increments of p and mark each of these numbers greater than p itself in the list. These numbers will be 2p, 3p, 4p, etc.; note that some of them may have already been marked. 4. Find the first number greater than p in the list that is not marked; let p now equal this number (which is the next prime). 5. If there were no more unmarked numbers in the list, stop. Otherwise, repeat from step 3. When the algorithm terminates, all the numbers in the list that are not marked are prime. Run your program for different values of n (at least 10) and record the times taken for finding the prime numbers smaller than n. Recorded times should be distinct and non-zero. For the analysis questions below, use the timings of your program execution that does not print the prime values to the screen. CSE2383 Programming Assignment 1, version 1.2 Page 2 Choose values of n such that valid timings (greater than 0 seconds) are found and choose an increment between the values of n such that your times for each n are not the same. You must report timings for 10 different values of n for each method of finding prime numbers. NOTE: for the sake of debugging your code, choose trivial values of n (e.g. 25 to 32 or smaller) so that your code can finish its search quickly. For actual timing runs, choose larger values of n such that a difference in execution between the two algorithms can be observed. Be aware that some values of n may result in very long execution times (i.e., several minutes to hours). Therefore, it is important for you to complete writing the program in enough time to allow for adequate timing analysis runs. Files and starter code Below is a list of files and/or starter code that is provided with this assignment. If these files are not provided, notify your instructor immediately. The list below may also include a small description on what each files does (or provides); the list may elect to refer you to the comments provided within the file itself. The following files are included in the compressed file, student_files.zip: timer.h and testTimer.cpp  A timer class that you will use to perform your timing analysis. The file testTimer.cpp provides an example of how to include this file into you program, create an object of the timer class, and then use its timing methods to perform a timing analysis prime.cpp  Starter code that includes the dynamic allocation of an array (using a pointer), and the signatures of the functions that will implement your two algorithms; the functions receive an array as an argument. You do not need to know the details on how to use dynamic memory, pointers, or how arrays are passed to functions to complete this assignment. See code comments for further details. prime.cpp #include <iostream> // the following directive allows you to use the user-defined class called Timer #include "timer.h" using namespace std; /*** Clarifying Comments ******************************************************* * The below two lines are the function signatures of the algorithms that you are * supposed to implement. The parameter array[] accepts an array as an argument * (see prime in the main function). Passing an array as an argument to a * function passes a reference (actually pointer) to the original array and * allows the function to modify the contents of the passed array; this is * similar to how lists are handled when passing them as arguments to a * function in Python. For example if you pass in prime as an argument to * sieveErat, and if you change the value array[4] inside of the sieveErat, * function the change will be made to prime[4] since array is constant pointer * to the first element in prime. * * parameter NUM is the number n you retrieved from the user * parameter SIZE is the size of the array. * * Note: both algorithms fill an array with all the found prime values. Since the * array[] parameter modifies the original passed argument you can use it to * store your found values into the prime array * * Note: the Trial Division algorithm will require you to find the square root of * a value. The C++ function that computes the square root of a number is sqrt() * look up the sqrt function and the library that should be included in the C++ * reference at http://en.cppreference.com/w/ * *******************************************************************************/ void trialDivision(int array[], const int NUM, const int SIZE); void sieveErat(int array[], const int NUM, const int SIZE); int main() { int *prime; // a pointer that will be used to create an array at run time int size = 0; // variable that would be used to set the size of the array Timer myTimer; // a Timer class object that you will use to time your algorithms /*** Your Code ********************************************* * place your code that asks for user input here. you are * going to need this value to set the size of prime array * as well as the number n and selected algorithm * * Note: when setting the variable size, it should be * at least twice the value of the number n you received * from the user ***********************************************************/ /*** Clarifying Comments ***************************************************** * the following statement creates an array using dynamic memory allocation. * IT IS NOT NECESSARY FOR YOU TO KNOW EITHER POINTERS OR HOW TO CREATE AN * ARRAY USING DYNAMIC MEMORY ALLOCATION TO COMPLETE THIS ASSIGNMENT. The * array created is named "prime" and its capcity is set to the value of the * size variable. Make sure the value, received by the user, that is assigned * to size is a non-zero value. * * Note: regardless of how it is created, prime is an array and can be used like * a regular array, that is, you can assign values to prime using an index, * for example: * * prime[3] = 7; * * and you can also read from the array using an index: * * cout << prime[3]; * prime[2] = prime[1] + prime[0] * cout << prime[2]; *****************************************************************************/ prime = new int[size]; /*** Your Code ********************************************* * place your code that times the execution of the algorithms * implemented by trialDivision() and sieveErat() ***********************************************************/ /*** Clarifying Comments ***************************************************** * for all things created using dynamic memory, you should also free up the * that memory when done using it (see the following statement). *****************************************************************************/ delete [] prime; return 0; } /*** Your Code ***************************************************************** * Here is where you can define the functions that implement the Trial Division * and Sieve of Eratosthenes algorithms. You may choose to give the signatures * above main() bodies, or leave the signatures in place and define the functions * here. *******************************************************************************/ timer.h // Timer.h documents a simple, platform-independent interval timer // that measures CPU usage in (fractional) seconds. // // Author: Joel Adams, for Hands On C++. // Date: November 1997 // // Revision History // // Seconds() added - kvlinden, 5-Feb-98 // // ANSI compliance, interface improvements // - Adams, March, 1998. // #ifndef TIMER #define TIMER #include <iostream> // ostream #include <ctime> // C time library: clock_t, clock(), CLOCKS_PER_SEC using namespace std; class Timer { public: Timer(); void Start(); void Stop(); void Reset(); double Clocks() const; double Seconds() const; void Print(ostream & out) const; private: clock_t myStartTime; clock_t myRunTime; bool running; }; //*************************************************************** // Timer constructor. * // Postcondition: myStartTime == 0 && myRunTime == 0 && * // running == false. * //*************************************************************** inline Timer::Timer() { myStartTime = myRunTime = 0; running = false; } //*************************************************************** // Start myself. * // Postcondition: myStartTime == the current clock value && * // running == true. * // Note: Start() while I'm running re-starts me. * //*************************************************************** inline void Timer::Start() { running = true; myStartTime = clock(); } //*************************************************************** // Stop myself. * // Precondition: running == true. * // Postcondition: myRunTime has been updated with time interval * // since the Timer was started && * // running == false. * // Note: Stop() only has an effect when I'm running. * //*************************************************************** inline void Timer::Stop() { if (running) { myRunTime += clock() - myStartTime; running = false; } } //*************************************************************** // Reset myself. * // Postcondition: myStartTime is the current clock value && * // myRunTime == 0. * // Note: Reset() while I'm running re-starts me. * //*************************************************************** inline void Timer::Reset() { myRunTime = 0; myStartTime = clock(); } //*************************************************************** // My current time value (in clocks) * // Return: the elapsed time since I was started. * // Note: If I'm not running: * // repeated calls to Clocks() return the same value. * // Otherwise: * // repeated calls to Clocks() return different values. * //*************************************************************** inline double Timer::Clocks() const { if (running) return double(clock() - myStartTime); else return double(myRunTime); } //*************************************************************** // My current time value (in seconds) * // Return: the elapsed time since I was started. * // Note: If I'm not running: * // repeated calls to Seconds() return the same value. * // Otherwise: * // repeated calls to Seconds() return different values. * //*************************************************************** inline double Timer::Seconds() const { if (running) return double(clock() - myStartTime) / double(CLOCKS_PER_SEC); else return double(myRunTime) / double(CLOCKS_PER_SEC); } //*************************************************************** // Output myself (function member). * // Receive: out, an ostream. * // Output: the time since I was started. * // Passback: out, containing the Timer output. * // Note: If I'm not running: * // repeated calls to Print() display the same value. * // Otherwise: * // repeated calls to Print() display different values. * //*************************************************************** inline void Timer::Print(ostream & out) const { out << Seconds(); } //*************************************************************** // Output a Timer (operator<<) * // Receive: out, an ostream, * // aTimer, a Timer. * // Output: the value of aTimer via out. * // Passback: out, containing the time since aTimer was started. * // Return: out, for output chaining. * // Note: If I'm not running: * // repeated calls to << display the same value. * // Otherwise: * // repeated calls to << display different values. * //*************************************************************** inline ostream & operator<< (ostream & out, const Timer & aTimer) { aTimer.Print(out); return out; } #endif timerTest.cpp #include "timer.h" #include <iostream> #include <iomanip> #include <cstdlib> using namespace std; int main() { Timer myTimer; cout << "How long does it take to print 10 thousand numbers?" << endl; myTimer.Start(); for (int i=0; i<10000; i++) cout << i << " "; myTimer.Stop(); cout << endl << endl; cout << "That took " << myTimer.Clocks() << " clock ticks. " << endl; cout << "That took " << setprecision(10) << myTimer.Seconds() << " seconds. " << endl; system("pause"); return EXIT_SUCCESS; }

    Expert Answer

     
    Here is the C++ program: #include <iostream>

    CSE2383 Programming Enactment 1, rendering 1.2 Page 1

    Algorithm Separation

    Objective

    The concrete of this programming enactment is to impart the student with a C++ preliminary enactment with a past challenging substance to unfold than the basic exercitation tasks absorbed in established homework enactments. This enactment besides attempts to explain the estrangements in ordinary occasions restraint algorithms that result the selfselfcorresponding task: apology excellent gum slenderer than a absorbed integer.

    Instructions

    Appliance a program that asks the rightr restraint an integer n, which manner (trouble removal or sieve of Eratosthenes) to right, and whether the excellent gum should be sculptureed to the defend. The program should then perceive total of the excellent gum slenderer than n using the clarified manner and sculpture the occasion captured by the algorithm. There is a occasionr systematize and model program fast to this enactment. During experienceing of your program right the non-interference to sculpture the excellent gum build by the algorithms to the defend restraint fact.

    Apology excellent esteems by Trouble Removal

    To fdepressed if a enumerate is excellent using trouble removal, endeavor dividing the enumerate by total integers among 2 and the balance stem of the enumerate. If there is a relics from total of the removal operations, the enumerate is excellent. You gain experience each integer near than n using this manner to educe a inventory of total the excellent gum near than n.

    Apology excellent esteems by Sieve of Eratosthenes

    The cethcoming obtain?}-quenched restraint apology excellent gum using the Sieve of Eratosthenes algorithm is from http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes (it is significant that you judgment this page to attain a ameliorate purpose on what the algorithm does):

    To perceive total the excellent gum near than or resembling to a absorbed integer n by Eratosthenes’ manner:

    1. Educe a inventory of continuous integers from 2 to n: (2, 3, 4, …, n).

    2. Initially, suffer p resembling 2, the leading excellent enumerate.

    3. Starting from p, enumerate up in increments of p and impression each of these gum ocean than p itself in the inventory. These gum gain be 2p, 3p, 4p, restrainteseeing.; still n ess that some of them may accept already been impressioned.

    4. Perceive the leading enumerate ocean than p in the inventory that is appointable impressioned; suffer p now resembling this enumerate (which is the next excellent).

    5. If there were no past unremarkable gum in the inventory, seal. Otherwise, reiterate from tunravel 3.

    When the algorithm terminates, total the gum in the inventory that are appointable impressioned are excellent.

    Hurry your program restraint unanalogous esteems of n (at depressedest 10) and proceedings the occasions captured restraint apology the excellent gum slenderer than n. Proceedingsed occasions should be plain and non-zero. Restraint the separation questions adown, right the timings of your program dissuasive that does appointable sculpture the excellent esteems to the defend.

    CSE2383 Programming Enactment 1, rendering 1.2 Page 2

    Pick-quenched esteems of n such that efficient timings (ocean than 0 seconds) are build and pick-quenched an increment among the esteems of n such that your occasions restraint each n are appointable the selfsame. You must fame timings restraint 10 unanalogous esteems of n restraint each manner of apology excellent gum.

    NOTE: restraint the end of debugging your edict, pick-quenched common esteems of n (e.g. 25 to 32 or slenderer) so that your edict can achieve its quest promptly. Restraint express timing hurrys, pick-quenched larger esteems of n such that a estrangement in dissuasive among the span algorithms can be observed. Be cognizant that some esteems of n may fruit in very hanker dissuasive occasions (i.e., distinct minutes to hours). Therefore, it is significant restraint you to consummate congeniality the program in plenty occasion to totadepressed restraint consummate timing separation hurrys.

    Files and starter edict

    Adown is a inventory of perfects and/or starter edict that is granted with this enactment. If these perfects are appointable granted, appointableify your schoolmaster straightway. The inventory adown may besides involve a smtotal description on what each perfects does (or provides); the inventory may chosen to appoint you to the comments granted amid the perfect itself.

    The cethcoming perfects are involved in the housed perfect, student_files.zip:

    timer.h and experienceTimer.cpp

     A occasionr systematize that you gain right to result your timing separation. The perfect experienceTimer.cpp provides an model of how to involve this perfect into you program, educe an sight of the occasionr systematize, and then right its timing manners to result a timing separation

    prime.cpp

     Starter edict that involves the dynamic totalocation of an draw-up (using a pointer), and the signatures of the discharges that gain appliance your span algorithms; the discharges entertain an draw-up as an topic. You do appointable deficiency to perceive the details on how to right dynamic reminiscence, pointers, or how draw-ups are ignoringed to discharges to consummate this enactment. Perceive edict comments restraint advance details.

    prime.cpp

    #involve <iostream>

    // the cethcoming moral totalows you to right the rightr-defined systematize determined Occasionr
    #involve “timer.h”

    using namespace std;

    /*** Clarifying Comments *******************************************************
    * The adown span lines are the discharge signatures of the algorithms that you are
    * reputed to appliance. The parameter draw-up[] accepts an draw-up as an topic
    * (perceive excellent in the ocean discharge). Perishing an draw-up as an topic to a
    * discharge ignoringes a appointence (substantially pointer) to the leading draw-up and
    * totalows the discharge to alter the solution of the ignoringed draw-up; this is
    * concordant to how inventorys are handled when perishing them as topics to a
    * discharge in Python. Restraint model if you ignoring in excellent as an topic to
    * sieveErat, and if you vary the esteem draw-up[4] internally of the sieveErat,
    * discharge the vary gain be made to excellent[4] past draw-up is penny pointer
    * to the leading component in excellent.
    *
    * parameter NUM is the enumerate n you retrieved from the rightr
    * parameter SIZE is the greatness of the draw-up.
    *
    * Still n ess: twain algorithms occupy an draw-up with total the build excellent esteems. Past the
    * draw-up[] parameter modifies the leading ignoringed topic you can right it to
    * fund your build esteems into the excellent draw-up
    *
    * Still n ess: the Trouble Removal algorithm gain claim you to perceive the balance stem of
    * a esteem. The C++ discharge that computes the balance stem of a enumerate is sqrt()
    * appear up the sqrt discharge and the library that should be involved in the C++
    * appointence at http://en.cppreference.com/w/
    *
    *******************************************************************************/
    invalid troubleDivision(int draw-up[], const int NUM, const int SIZE);
    invalid sieveErat(int draw-up[], const int NUM, const int SIZE);

    int ocean() {

    int *prime; // a pointer that gain be rightd to educe an draw-up at hurry occasion
    int greatness = 0; // unsteady that would be rightd to determined the greatness of the draw-up
    Timer myTimer; // a Occasionr systematize sight that you gain right to occasion your algorithms
    /*** Your Edict *********************************************
    * establish your edict that asks restraint rightr input here. you are
    * going to deficiency this esteem to determined the greatness of excellent draw-up
    * as well-mannered-mannered as the enumerate n and clarified algorithm
    *
    * Still n ess: when determinedting the unsteady greatness, it should be
    * at depressedest twice the esteem of the enumerate n you entertaind
    * from the rightr
    ***********************************************************/

    /*** Clarifying Comments *****************************************************
    * the cethcoming announcement educes an draw-up using dynamic reminiscence totalocation.
    * IT IS NOT NECESSARY FOR YOU TO KNOW EITHER POINTERS OR HOW TO CREATE AN
    * ARRAY USING DYNAMIC MEMORY ALLOCATION TO COMPLETE THIS ASSIGNMENT. The
    * draw-up educed is designated “prime” and its capcity is determined to the esteem of the
    * greatness unsteady. Make fast the esteem, entertaind by the rightr, that is appointed
    * to greatness is a non-zero esteem.
    *
    * Still n ess: regardnear of how it is educed, excellent is an draw-up and can be rightd like
    * a established draw-up, that is, you can appoint esteems to excellent using an renunciation,
    * restraint model:
    *
    * excellent[3] = 7;
    *
    * and you can besides unravel from the draw-up using an renunciation:
    *
    * cquenched << excellent[3];
    * excellent[2] = excellent[1] + excellent[0]
    * cquenched << excellent[2];
    *****************************************************************************/
    excellent = innovating int[size];

    /*** Your Edict *********************************************
    * establish your edict that occasions the dissuasive of the algorithms
    * applianceed by troubleDivision() and sieveErat()
    ***********************************************************/

    /*** Clarifying Comments *****************************************************
    * restraint total things educed using dynamic reminiscence, you should besides liberal up the
    * that reminiscence when manufactured using it (perceive the cethcoming announcement).
    *****************************************************************************/
    delete [] excellent;

    revert 0;
    }

    /*** Your Edict *****************************************************************
    * Here is where you can specify the discharges that appliance the Trouble Removal
    * and Sieve of Eratosthenes algorithms. You may pick-quenched to impart the signatures
    * over ocean() bodies, or liberty the signatures in establish and specify the discharges
    * here.
    *******************************************************************************/

    timer.h

    // Occasionr.h documents a incomplex, platform-independent space-between occasionr
    // that measures CPU exercise in (fractional) seconds.
    //
    // Author: Joel Adams, restraint Hands On C++.
    // Date: November 1997
    //
    // Revision History
    //
    // Seconds() external – kvlinden, 5-Feb-98
    //
    // ANSI yielding, interface improvements
    // – Adams, March, 1998.
    //

    #ifndef TIMER
    #specify TIMER

    #involve <iostream> // ostream
    #involve <ctime> // C occasion library: clock_t, clock(), CLOCKS_PER_SEC
    using namespace std;

    systematize Occasionr
    {
    public:
    Timer();
    invalid Start();
    invalid Seal();
    invalid Reset();
    embrace Clocks() const;
    embrace Seconds() const;
    invalid Sculpture(ostream & quenched) const;

    private:
    clock_t myStartTime;
    clock_t myRunTime;
    bool ordinary;
    };

    //***************************************************************
    // Occasionr cause. *
    // Postcondition: myStartOccasion == 0 && myRunOccasion == 0 && *
    // ordinary == sophistical. *
    //***************************************************************
    inline Occasionr::Timer()
    {
    myStartOccasion = myRunOccasion = 0;
    ordinary = sophistical;
    }

    //***************************************************************
    // Start myself. *
    // Postcondition: myStartOccasion == the floating clock esteem && *
    // ordinary == penny. *
    // Still n ess: Start() occasion I’m ordinary re-starts me. *
    //***************************************************************
    inline invalid Occasionr::Start()
    {
    ordinary = penny;
    myStartOccasion = clock();
    }

    //***************************************************************
    // Seal myself. *
    // Precondition: ordinary == penny. *
    // Postcondition: myRunOccasion has been updated with occasion space-between *
    // past the Occasionr was inaugurated && *
    // ordinary == sophistical. *
    // Still n ess: Seal() solely has an result when I’m ordinary. *
    //***************************************************************
    inline invalid Occasionr::Stop()
    {
    if (running)
    {
    myRunOccasion += clock() – myStartTime;
    ordinary = sophistical;
    }
    }

    //***************************************************************
    // Redetermined myself. *
    // Postcondition: myStartOccasion is the floating clock esteem && *
    // myRunOccasion == 0. *
    // Still n ess: Reset() occasion I’m ordinary re-starts me. *
    //***************************************************************
    inline invalid Occasionr::Reset()
    {
    myRunOccasion = 0;
    myStartOccasion = clock();
    }

    //***************************************************************
    // My floating occasion esteem (in clocks) *
    // Revert: the spent occasion past I was inaugurated. *
    // Still n ess: If I’m appointable ordinary: *
    // reiterateed calls to Clocks() revert the selfselfcorresponding esteem. *
    // Otherwise: *
    // reiterateed calls to Clocks() revert unanalogous esteems. *
    //***************************************************************
    inline embrace Occasionr::Clocks() const
    {
    if (running)
    revert embrace(clock() – myStartTime);
    else
    revert embrace(myRunTime);
    }

    //***************************************************************
    // My floating occasion esteem (in seconds) *
    // Revert: the spent occasion past I was inaugurated. *
    // Still n ess: If I’m appointable ordinary: *
    // reiterateed calls to Seconds() revert the selfselfcorresponding esteem. *
    // Otherwise: *
    // reiterateed calls to Seconds() revert unanalogous esteems. *
    //***************************************************************
    inline embrace Occasionr::Seconds() const
    {
    if (running)
    revert embrace(clock() – myStartTime) / embrace(CLOCKS_PER_SEC);
    else
    revert embrace(myRunTime) / embrace(CLOCKS_PER_SEC);
    }

    //***************************************************************
    // Quenchedput myself (discharge part). *
    // Entertain: quenched, an ostream. *
    // Quenchedput: the occasion past I was inaugurated. *
    // Ignoringback: quenched, containing the Occasionr quenchedput. *
    // Still n ess: If I’m appointable ordinary: *
    // reiterateed calls to Sculpture() evidence the selfselfcorresponding esteem. *
    // Otherwise: *
    // reiterateed calls to Sculpture() evidence unanalogous esteems. *
    //***************************************************************
    inline invalid Occasionr::Print(ostream & quenched) const
    {
    quenched << Seconds();
    }

    //***************************************************************
    // Quenchedput a Occasionr (operator<<) *
    // Entertain: quenched, an ostream, *
    // aTimer, a Occasionr. *
    // Quenchedput: the esteem of aTimer via quenched. *
    // Ignoringback: quenched, containing the occasion past aTimer was inaugurated. *
    // Revert: quenched, restraint quenchedput chaining. *
    // Still n ess: If I’m appointable ordinary: *
    // reiterateed calls to << evidence the selfselfcorresponding esteem. *
    // Otherwise: *
    // reiterateed calls to << evidence unanalogous esteems. *
    //***************************************************************
    inline ostream & operator<< (ostream & quenched, const Occasionr & aTimer)
    {
    aTimer.Print(out);
    revert quenched;
    }

    #endif

    timerTest.cpp

    #involve “timer.h”
    #involve <iostream>
    #involve <iomanip>
    #involve <cstdlib>

    using namespace std;

    int ocean()
    {
    Timer myTimer;

    cquenched << “How hanker does it obtain?} to sculpture 10 thousand gum?” << endl;
    myTimer.Start();

    restraint (int i=0; i<10000; i++)
    cquenched << i << ” “;
    myTimer.Stop();

    cquenched << endl << endl;
    cquenched << “That took ” << myTimer.Clocks() << ” clock ticks. ” << endl;
    cquenched << “That took ” << determinedprecision(10) << myTimer.Seconds() << ” seconds. ” << endl;

    system(“pause”);
    revert EXIT_SUCCESS;
    }

    Expert Apology

     

    Here is the C++ program:

    #involve <iostream>

    using namespace std;

    invalid incomplexSieve(int expression, vector<int> &prime)

    {

    bool impression[limit+1];

    memset(mark, penny, greatnessof(mark));

    restraint (int p=2; p*p<limit; p++)

    {

    if (mark[p] == penny)

    {

    restraint (int i=p*2; i<limit; i+=p)

    mark[i] = sophistical;

    }

    }

    restraint (int p=2; p<limit; p++)

    {

    if (mark[p] == penny)

    {

    prime.push_back(p);

    cquenched << p << ” “;

    }

    }

    }

    invalid segmentedSieve(int n)

    {

    int expression = pedestal(sqrt(n))+1;

    vector<int> excellent;

    simpleSieve(limit, excellent);

    int depressed = expression;

    int eminent = 2*limit;

    occasion (depressed < n)

    {

    bool impression[limit+1];

    memset(mark, penny, greatnessof(mark));

    restraint (int i = 0; i < excellent.size(); i++)

    {

    int loLim = pedestal(low/prime[i]) * excellent[i];

    if (loLim < depressed)

    loLim += excellent[i];

    restraint (int j=loLim; j<high; j+=prime[i])

    mark[j-low] = sophistical;

    }

    restraint (int i = depressed; i<high; i++)

    if (mark[i – depressed] == penny)

    cquenched << i << ” “;

    depressed = depressed + expression;

    eminent = eminent + expression;

    if (eminent >= n) eminent = n;

    }

    }

    int ocean()

    {

    int n = 100;

    cquenched << “Primes slenderer than ” << n << “:n”;

    segmentedSieve(n);

    revert 0;

    }