This won't take much time

Find the number of primes under 123456789.


The answer is 7027260.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Pranjal Jain
Jun 2, 2016
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#include<bits/stdc++.h>
using namespace std;
bool alpha[123456790];
void solve(){
    memset(alpha,1,sizeof alpha);
    alpha[0]=alpha[1]=0;
    int ans=0;
    for(int i=2;i<123456790;i++){
        if(alpha[i]){
            ans++;
            if(1LL*i*i<123456790){
                int j=i*i;
                while(j<123456790){
                    alpha[j]=false;
                    j+=i;
                 }
            }
        }
     }
    cout<<ans;
}

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...