Pagini recente » Cod sursa (job #611744) | Cod sursa (job #633339) | Istoria paginii runda/eusebiu_oji_2003_cls10/clasament | Profil cristinica | Cod sursa (job #2225512)
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int sir[2000001];
int main() {
FILE* ip;
FILE* op;
ip = fopen("ciur.in", "r");
if (ip == NULL) {
perror("Cannot open input file");
return 1;
}
op = fopen("ciur.out", "w");
if (op == NULL) {
perror("Cannot open output file");
return 1;
}
int n;
fscanf(ip, "%d", &n);
for (int i = 2; i <= n; i++) {
if (sir[i] != -1) {
for (int j = i * 2; j <= n; j += i) {
sir[j] = -1;
}
}
}
int primes = 0;
for (int i = 2; i <= n; i++) {
if (sir[i] != -1) {
primes++;
}
}
fprintf(op, "%d", primes);
fclose(ip);
fclose(op);
return 0;
}