Advertisement
Guest User

Untitled

a guest
May 21st, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. //C++
  2.  
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main(){
  7. int n;
  8. bool prim;
  9. cin >> n;
  10. prim = false;
  11. while(! prim){
  12. n++;
  13. prim = true;
  14. if(n<2)
  15. prim = false;
  16. if(n % 2 == 0 && n > 2)
  17. prim = false;
  18. for(int d = 3 ; d * d <= n ; d += 2)
  19. if(n % d == 0)
  20. prim = false;
  21.  
  22. }
  23. cout << n;
  24. return 0;
  25. }
  26.  
  27.  
  28.  
  29. //Python
  30.  
  31. def primality(n):
  32. if n < 2:
  33. return False
  34. if n < 4:
  35. return True
  36. if n % 2 == 0:
  37. return False
  38. i = 3
  39. while i * i <= n:
  40. if n % i == 0:
  41. return False
  42. i += 2
  43. return True
  44.  
  45. x = int(raw_input())
  46. done = False
  47. i = x + 1
  48. while done == False:
  49. if primality(i) == True:
  50. print(i)
  51. done = True
  52. i += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement