Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include <vector>
  2. #include <cstdio>
  3. #include <math.h>
  4. using namespace std;
  5. const int maxv = 1000000;
  6. int n,m, prime[maxv + 1];
  7. void eratos(){
  8. prime[0] = prime[1] = 1;
  9. int sq = (int)sqrt(maxv);
  10. for(int i=2;i<= sq; ++i) {
  11. if(prime[i]) continue;
  12. for(int j=i*i; j<= maxv; j += i) {
  13. prime[j] = 1;
  14. }
  15. }
  16. }
  17.  
  18. int main(){
  19. eratos();
  20. scanf("%d %d",&n,&m);
  21. for(int i=n; i<=m; ++i) {
  22. if(!prime[i]){
  23. printf("%d\n",i);
  24. }
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement