Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool SqrtN(int x)
- {
- double d = Math.Ceiling(Math.Sqrt(x));
- for (int i = 2; i < d; i++) {
- if (x % i == 0) {
- return false;
- }
- }
- return true;
- }
- public static bool Eratostenes(int x)
- {
- int[] first = new int[x];
- int index = 0;
- for (int i = 1; i < x; i++)
- {
- if (SqrtN(i))
- {
- first[index] = i;
- }
- index++;
- }
- for (int i = 0; i < x; i++)
- {
- if (first[i] == x)
- {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement