Advertisement
Norby9

Untitled

Sep 22nd, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. #define nmax 1000001
  6.  
  7. bool v[nmax] ={} ;
  8.  
  9. void ciur()
  10. {
  11. v[0] = v[1] = 1 ;
  12.  
  13. for(int i = 4 ; i <= nmax ; i +=2)
  14. v[i] = 1 ;
  15. for(int i = 3 ; i <= nmax ; i += 2)
  16. if(v[i] == 0)
  17. for(int j = i ; j <= (nmax / i) ; ++ j)
  18. v[j * i] = 1 ;
  19. }
  20.  
  21. int main()
  22. {
  23. int n , counter = 0 , a[nmax] ;
  24.  
  25. ciur() ;
  26.  
  27. cin >> n ;
  28.  
  29. for(int i = 1 ; i <= n ; ++ i)
  30. {
  31. cin >> a[i] ;
  32.  
  33. if(v[a[i]] == 0) counter ++ ;
  34. }
  35.  
  36. cout << counter ;
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement