fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7. bool czy_pierwsza(int n) {
  8.  
  9. int d=2;
  10.  
  11. while (d*d<=n) {
  12.  
  13. if (n%d==0) return false;
  14.  
  15. d+=1;
  16.  
  17. }
  18.  
  19. return true;
  20.  
  21. }
  22.  
  23. int pierwsza(int n) {
  24.  
  25. int numer =0;
  26.  
  27. int i=2;
  28.  
  29. while (numer !=n) {
  30.  
  31. if (czy_pierwsza(i)) numer += 1;
  32.  
  33. i +=1;
  34.  
  35. }
  36.  
  37. return i-1;
  38.  
  39. }
  40.  
  41. int main() {
  42.  
  43. cout<<pierwsza(7)<<" "<<pierwsza(25)<<endl;
  44.  
  45. return 0;
  46.  
  47. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
17 97