Advertisement
Guest User

tmp

a guest
Nov 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. public static bool SqrtN(int x)
  2. {
  3. double d = Math.Ceiling(Math.Sqrt(x));
  4. for (int i = 2; i < d; i++) {
  5. if (x % i == 0) {
  6. return false;
  7. }
  8. }
  9. return true;
  10. }
  11.  
  12. public static bool Eratostenes(int x)
  13. {
  14. int[] first = new int[x];
  15. int index = 0;
  16. for (int i = 1; i < x; i++)
  17. {
  18. if (SqrtN(i))
  19. {
  20. first[index] = i;
  21. }
  22. index++;
  23. }
  24.  
  25. for (int i = 0; i < x; i++)
  26. {
  27. if (first[i] == x)
  28. {
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement