Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const long long MAX=100;
- bool Primes[MAX];
- int main()
- {
- int ilosc_pierwszych;
- long long n;
- cin>>n;
- while(n!=0)
- {
- ilosc_pierwszych=0;
- for(int i=0;i<=MAX;i++)
- {
- Primes[i]=1;
- }
- Primes[0]=0;
- Primes[1]=0;
- for(int i=2;i*i<=MAX;i++)
- {
- if(Primes[i]==1)
- {
- for(int j=2;j*i<=n;j++)
- {
- Primes[i*j]=0;
- }
- }
- }
- for(int k=0;k<=n;k++)
- {
- if(Primes[k]==1)
- {
- ilosc_pierwszych++;
- }
- }
- if(Primes[n]==0)
- {
- cout<<n<<" nie jest pierwsza."<<endl;
- }
- if(Primes[n]==1)
- {
- cout<<n<<" to liczba pierwsza numer "<<ilosc_pierwszych<<"."<<endl;
- }
- cin>>n;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement