Spoj TDPRIMES - Printing some primes Solution
Problem Link: https://www.spoj.com/problems/TDPRIMES/
Solution in C++:
- #include<bits/stdc++.h>
- using namespace std;
- vector<bool>v(100000000,true);
- int ar[8000000];
- int main()
- {
- long long int n=100000000,i,j;
- v[1]=v[0]=false;
- for(i=4; i<=n; i+=2)v[i]=false;
- for(i=3; i*i<=n; i+=2)
- {
- if(v[i])
- {
- for(j=i*i; j<=n; j=j+(2*i))
- {
- v[j]=false;
- }
- }
- }
- j=0;
- ar[0]=2;
- for(i=3; i<=n; i+=2)
- {
- if(v[i])
- ar[++j]=i;
- }
- for(i=1; i<=j; i+=100)
- cout<<ar[i-1]<<endl;
- return 0;
- }
No comments