Cod sursa(job #1892475)

Utilizator romykPrehari Romica romyk Data 24 februarie 2017 23:26:34
Problema Ciurul lui Eratosthenes Scor 90
Compilator c Status done
Runda Arhiva educationala Marime 1.47 kb
#include <stdio.h>
#include <stdbool.h>

#define MAXSIZE 400000001
#define S 6
#define U 1

long long i,n,p,j,j2,i1,i2,i22,i11,k;
int m=2,s;
bool a[MAXSIZE];
int main()
{
    freopen("ciur.in", "r", stdin);
    freopen("ciur.out", "w", stdout);

    scanf("%d", &n);

    for(i= S ; i <=n ; i += S)
    {
        i1 = i - U;
        i2 = i + U;
        if(a [ i1 ] ==0)
        {
            m++;
            for(j= i ; (j-1) * i1  <=n ; j += S)
            {
                    a[(j+1)*i1] = 1;
                    a[(j-1)*i1] = 1;
            }
        }

        if( a [ i2 ] == 0)
        {   m++;
            for(j= i ; (j-1) * i2  <=n ; j += S)
            {
                    a[(j+1)*i2] = 1;
                    a[(j-1)*i2] = 1;
            }
        }


    }
/*
    for(i= S ; i <=n ; i += S)
    {
        i1 = i - U;
        i2 = i + U;
        if(! a [ i1 ])
        {
         m++;
            i11 = i1*S;
            for( j =i11 + i1, j2 = i1 * i1 ; j<= n; j += i11, j2 += i11 )
                {

                    a[j]=1;
                    if( j2 <= n)
                    {
                    a[j2]=1;
                    }
                }
        }

        if(! a [ i2 ] )
        {             m++;
            i22 = i2*S;
            for(j = i22 + i2 ; j <= n ; j += i22)
                {
                a[j]=1;
                }

        }
     }*/
     printf("%d\n" , m);
     return 0;
}