Cod sursa(job #1829599)

Utilizator dobrandreiAndrei Dobra dobrandrei Data 15 decembrie 2016 13:09:16
Problema Ciurul lui Eratosthenes Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <stdio.h>

using namespace std;
FILE *f,*g;
int v[100];
int main()
{
    int n,i,j,nrp=0;
    f=fopen("prime.in","r");
    g=fopen("prime.out","w");
    fscanf(f,"%d",&n);
    for(i=2;i<=n;i++)
    {
        if(v[i]==0)
        {
            for(j=i*2;j<=n;j+=i)
            {
                v[j]=1;
            }
            nrp++;
        }
    }
    fprintf(g,"%d",nrp);
    return 0;
}