Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const long long MAX=100;
  6. bool Primes[MAX];
  7.  
  8. int main()
  9. {
  10.  
  11. int ilosc_pierwszych;
  12. long long n;
  13.  
  14. cin>>n;
  15.  
  16. while(n!=0)
  17. {
  18. ilosc_pierwszych=0;
  19. for(int i=0;i<=MAX;i++)
  20. {
  21. Primes[i]=1;
  22. }
  23. Primes[0]=0;
  24. Primes[1]=0;
  25.  
  26. for(int i=2;i*i<=MAX;i++)
  27. {
  28. if(Primes[i]==1)
  29. {
  30. for(int j=2;j*i<=n;j++)
  31. {
  32. Primes[i*j]=0;
  33. }
  34. }
  35.  
  36. }
  37.  
  38. for(int k=0;k<=n;k++)
  39. {
  40. if(Primes[k]==1)
  41. {
  42. ilosc_pierwszych++;
  43. }
  44. }
  45. if(Primes[n]==0)
  46. {
  47. cout<<n<<" nie jest pierwsza."<<endl;
  48. }
  49. if(Primes[n]==1)
  50. {
  51. cout<<n<<" to liczba pierwsza numer "<<ilosc_pierwszych<<"."<<endl;
  52. }
  53. cin>>n;
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement