All pastes #815437 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2007-12-14 01:49 UTC
rendered paste body
#include <iostream>#include <vector>#define classdef typedef#include <iomanip>using namespace std;namespace{	classdef vector <unsigned> CVUInt;	typedef CVUInt::size_type TypeInd_t;	void AffichVect (const CVUInt & Tab)    {        TypeInd_t  Nb = 10;        for (TypeInd_t i = 0; i < Tab.size(); ++i)        {            cout << setw (5) << Tab [i];            if (0 == --Nb)            {                cout << '\n';                Nb = 10;            }        }        if (Nb > 0) cout << '\n';    } // AffichVect()	void GenerPrimesInfEqN (CVUInt & LesPremiers, unsigned N)    {        LesPremiers.resize ((N + 1) / 2);    // Initialiser le tableau avec les premiers entiers naturels impairs        LesPremiers [0] = 2;        unsigned NbElem = 1;        unsigned i = 3;        while (i <= N)        {            LesPremiers [NbElem] = i;            ++NbElem;            i += 2;        }        unsigned j;        i = 1;        while (LesPremiers [i] * LesPremiers [i] <= N)        {            // Supprimer les multiples de LesPremiersi            if (LesPremiers [i] != 0)            {                j = i + LesPremiers [i];                while (j < NbElem)                {                    LesPremiers [j] = 0;                    j += LesPremiers [i];                }            }            ++i;        }        j = 0;        for (unsigned i =0; i < NbElem ; ++i)        {            if (LesPremiers [i] != 0)            {                LesPremiers [j] = LesPremiers [i];                ++j;            }        }        LesPremiers.resize (j);    }} //namespaceint main (void){    CVUInt MonVector;        unsigned N;    cout << "Saisissez N : ";    cin >> N;    GenerPrimesInfEqN (MonVector, N);    cout << "N saisi : " << N << endl;        AffichVect (MonVector);    return 0;}