N
N
Nikita Nigmatullin2017-01-27 14:06:05
Programming
Nikita Nigmatullin, 2017-01-27 14:06:05

I came up with an algorithm, evaluate its fidelity?

I came up with an algorithm based on the Eratosphere sieve, evaluate its accuracy

int main() {
  bool *A;
  long N;
  cin >> N;
  
  A = new bool[N * 100 + 1];

  int i, k;

  for (int i = 2; i <= N * 100; i++)
    A[i] = true;
  k = 2;

  while (k * k <= N * 100) {
    if (A[k]) {
      i = k * k;
      while (i <= N * 100)
      {
        A[i] = false;
        i += k;
      }
    }
    k++;
  }
  int j = 0;
  for (int i = 2; i <= N * 100; i++) {
    if (A[i] && j < N) {
      cout << i << " ";
      j++;
    }
    if (j == N)
      break;
  }


  return 0;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2017-01-27
@Rsa97

Sorry. You did not come up with an algorithm, Eratosthenes invented it, you just implemented it.

X
x67, 2017-01-27
@x67

Algorithm:
Until we reach the goal, we move towards the goal.
Implementations:
a80fe3d9fa364451a455f63457eddb6f.jpeg65285528bc3f4a2fb0f329b9c41ca07d.jpeg8467581985144cb39723a1b2b3908848.jpeg2c6e523822d9458dbdad7277d710ffb0.jpeg84ee6adcd6d14aea822d32730bbae7f1.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question