fork download
  1. #include <iostream>
  2. using namespace std;
  3. int ile;
  4.  
  5. bool prawda(int n)
  6. {
  7. if(n<=2)
  8. return true;
  9.  
  10. for(int i=2;i*i<=n;i++)
  11. if(n%i==0)
  12. return false;
  13. return true;
  14. }
  15. int main()
  16. {
  17. cout << "Sprawdzimy teraz liczby pierwsze" << endl;
  18. cin>>ile;
  19. if(ile>10000)
  20. {
  21. cout<<"Za duza liczba!"<<endl;
  22. }
  23. else{
  24. for(int n=1; n<=ile; n++)
  25. {
  26. if (prawda(n))
  27. cout<<n<<" Tak"<<endl;
  28. else
  29. cout<<n<<" Nie"<<endl;
  30. }
  31. }
  32. return 0;
  33. }
Success #stdin #stdout 0s 15240KB
stdin
3
11
1
4
stdout
Sprawdzimy teraz liczby pierwsze
1 Tak
2 Tak
3 Tak