fork(1) 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 && n != d) 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. int main() {
  24. cout << pierwsza(7) << " " << pierwsza(25) << endl;
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
17 97