Cod sursa(job #2641341)
Utilizator | Data | 11 august 2020 09:22:51 | |
---|---|---|---|
Problema | Ciurul lui Eratosthenes | Scor | 20 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.52 kb |
#include <stdio.h>
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
freopen("ciur.in", "r", stdin);
freopen("ciur.out", "w", stdout);
int n, tot = 0, i;
for (scanf("%d", &n); n > 0; n--)
{
if (n % 2 == 1 && n > 2) {
bool gasit = false;
for (i = 3; i <= n / 2 && !gasit; i += 2) {
if (n % i == 0) gasit = true;
}
if (!gasit) tot++;
}
else if (n == 2) tot++;
}
printf("%d", tot);
return 0;
}