fork download
  1. #include <iostream>
  2. using namespace std;
  3. // zdefiniuj funkcję
  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. int pierwsza(int n) {
  13. int numer =0;
  14. int i=2;
  15. while (numer != n){
  16. if (czy_pierwsza(i)) numer += 1;
  17. i += 1;
  18. }
  19. return i-1;
  20. }
  21.  
  22. int main() {
  23. // sprawdź działanie funkcji
  24. cout << pierwsza(7) << " " << pierwsza(25) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
17 97