Pagini recente » Cod sursa (job #630279) | Cod sursa (job #2821096) | Cod sursa (job #56767) | Cod sursa (job #717672) | Cod sursa (job #557798)
Cod sursa(job #557798)
# include <fstream.h>
# include <time.h>
long n;
time_t t1, t2;
char a[(10000000 >> 3) + 1];
ifstream f ("ciur.in");
ofstream g ("ciur.out");
void ciur_bazat (){
long sol = 1;
for (long j = 4; j <= n; j += 2, a[j >> 3] |= (1 << (j & 7) ) );
for (long i = 3; i <= n; i += 2){
if (!(a[i >> 3] & (1 << (i & 7) ) ) ){
for (long j = i * 3, x = i << 1; j <= n; j += x) a[j >> 3] |= (1 << (j & 7) );
++sol;
}
}
g << sol << '\n';
}
int main (){
t1 = clock ();
f >> n; ciur_bazat ();
t2 = clock ();
g << (double)(t2 - t1) / 1000;
return 0;
}