# Cod sursa(job #2749116)

Utilizator Data 5 mai 2021 00:37:03 Ciurul lui Eratosthenes 100 cpp-64 done Arhiva educationala 1.71 kb
``````#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <iomanip>
#include <array>
#include <fstream>

using namespace std;

void printVector(vector<int64_t> v) {
for (auto& el : v) {
cout << el << " ";
}
cout << "\n";
}

int64_t maxim = v[0], indice = 0;
for (int i = 0; i < v.size() - 1; i++) {
if (v[i] < v[i + 1] && maxim < v[i + 1]) {
maxim = v[i + 1];
indice = i + 1;

}
else if (v[i] > v[i + 1] && maxim < v[i]) {
maxim = v[i];
indice = i;
}
}

return maxim;
}

int maxim(vector<int64_t> v) {
int64_t m = v[0];
for (auto el : v) {
m = max(el, m);
}
return m;
}

vector<int64_t> generateRandomVector(int64_t n, int64_t left, int64_t right) {
srand(time(NULL));

int64_t space = right - left;
vector <int64_t> v;
for (int i = 0; i < n; i++) {
int64_t el = rand() % space + left;
v.push_back(el);
}
return v;
}

int64_t maxVector(vector<int64_t> a) {
int64_t m = a[0];
for (int i = 1; i < a.size(); i++) {
m = max(a[i], m);
}
return m;
}

int64_t maximIndiceVector(vector<int64_t> a) {
int64_t m = a[0];
int indice = 0;
for (int i = 1; i < a.size(); i++) {
if (a[i] > m) {
m = a[i];
indice = i;
}
}
return indice;
}

int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}

int main()
{
ifstream fin("ciur.in");
ofstream fout("ciur.out");
int64_t n, numerePrime;
fin >> n;
vector <bool> estePrim(n+1, true);
numerePrime = 0;
for (int i = 2; i <= n; i++) {
if (estePrim[i] == true) {
numerePrime++;
for (int j = i*2; j <= n; j += i) {
estePrim[j] = false;
}
}
}
fout << numerePrime;
}
``````