fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool czy_pierwsza(int n) {
  5. int d=2;
  6. while (d*d<=n) {
  7. if (n%d==0) return false;
  8. d+=1;
  9. }
  10. return true;
  11. }
  12.  
  13. int pierwsza(int n) {
  14. int numer =0;
  15. int i=2;
  16. while (numer != n) {
  17. if (czy_pierwsza(i)) numer += 1;
  18. i += 1;
  19. }
  20. return i-1;
  21. }
  22.  
  23.  
  24. int main() {
  25. cout<<pierwsza(7)<< " "<<pierwsza(25)<<endl;
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
17 97