Cod sursa(job #2781464)

Utilizator andrei_marciucMarciuc Andrei andrei_marciuc Data 9 octombrie 2021 17:05:36
Problema Ciurul lui Eratosthenes Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <stdio.h>
unsigned char ciur[ ( 1 << 18 ) ];
 
int main()
{
    int n;
 
    FILE *fin = fopen( "ciur.in", "r" );
    fscanf( fin, "%d", &n );
    fclose( fin );
 
    int no = 1;
    for( int i = 3; i * i <= n; i += 2 )
        if( !( ciur[ i >> 3 ] & ( 1 << ( ( i >> 1 ) & 7 ) ) ) )
            for( int j = i * i; j <= n; j += i + i )
                ciur[ j >> 3 ] |= 1 << ( ( j >> 1 ) & 7 );

    for( int i = 3; i <= n; i += 2 )
        if( !( ciur[ i >> 3 ] & ( 1 << ( ( i >> 1 ) & 7 ) ) ) )
            ++no;
 
    FILE *fout = fopen( "ciur.out", "w" );
    fprintf( fout, "%d\n", no );
    fclose( fout );
    return 0;
}