Pagini recente » Cod sursa (job #831386) | Cod sursa (job #2527881) | Cod sursa (job #2630174) | Cod sursa (job #868535) | Cod sursa (job #340375)
Cod sursa(job #340375)
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define MY_FILE_NAME "ciur"
void read_data( int *n )
{
FILE *f = fopen( MY_FILE_NAME".in", "r" );
fscanf( f, "%i", n );
}
void write_response( long long response )
{
FILE *f = fopen( MY_FILE_NAME".out", "w" );
fprintf( f, "%lli", response );
}
void run();
int main()
{
#ifdef _MSC_VER
unsigned int start_tick = GetTickCount();
//time_t start_time = time( NULL );
#endif
run();
#ifdef _MSC_VER
//int secs = (int) (time( NULL ) - start_time);
//printf( "***** %i secs\n", secs );
int milis = GetTickCount() - start_tick;
printf( "***** %i milis\n", milis );
#endif
return 0;
}
void run()
{
int n = 0;
int response = 0;
static char v[1 + 2000000];
read_data( &n );
v[(1-1)/2] = 1; // neprime 1
response = 1; // pt 2
for ( int i = 3; i <= n; i+=2 ) {
if ( !v[(i-1)/2] ) {
response ++;
for ( int j = i + i+i; j <= n; j += 2*i )
v[(j-1)/2] = 1;
}
}
write_response( response );
}