Guest User

Untitled

a guest
May 24th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #include <string>
  4.  
  5. #include <cmath>
  6.  
  7.  
  8.  
  9. using namespace std;
  10.  
  11.  
  12.  
  13.  
  14.  
  15. bool esPrimo(int n) {
  16.  
  17.  
  18.  
  19. if(n==1) return 0;
  20.  
  21. if(n<4) return 1;
  22.  
  23. if(n%2==0) return 0;
  24.  
  25. if(n<9) return 1;
  26.  
  27. if(n%3==0) return 0;
  28.  
  29.  
  30.  
  31. else {
  32.  
  33.  
  34.  
  35.  
  36.  
  37. for(int j=1;j*j<=n;j+=6){
  38.  
  39. if(n%j==0) return 0;
  40.  
  41. if(n%(j+2)==0) return 0;
  42.  
  43.  
  44.  
  45. }
  46.  
  47.  
  48.  
  49. return 1;
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61. }
  62.  
  63.  
  64.  
  65. int main() {
  66.  
  67.  
  68.  
  69. int ret=0;
  70.  
  71. int count=0;
  72.  
  73.  
  74.  
  75. for(int j=1;;j++){
  76.  
  77.  
  78.  
  79. if(esPrimo(j)) {
  80.  
  81. cout << j << " es primo" << endl;
  82.  
  83. count++;
  84.  
  85. if(count==10001) {ret=j;break;}
  86.  
  87. }
  88.  
  89.  
  90.  
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. cout<< "Return: " << ret << endl;
  100.  
  101. }
Add Comment
Please, Sign In to add comment