Answer the question
In order to leave comments, you need to log in
How can the code be optimized to find prime numbers in a given range?
Actually, I did a challenge on codewars, the essence of which is as follows: you need to find the first pair of prime numbers in a given range with a given interval of prime numbers. I have implemented an algorithm that passes all tests, but ran into a runtime problem (my "top" code takes more than 12 seconds to complete). And I don't know how to optimize it yet. I immediately apologize for the pain in my eyes when viewing my code (I have been doing JS for the 4th week). And now to the point, the function, respectively, has 3 parameters:
/*
g (integer >= 2) интервал между простыми числами
m (integer > 2) начало заданного интервала (включительно)
n (integer >= m) конец заданного интервала (включительно)
*/
function gap(g, m, n) {
// Your code
}
gap(2, 3, 50); // [3, 5]
gap(2, 5, 5); // null
gap(2, 5, 7); // [5, 7]
gap(4, 130, 200); // [163, 167]
gap(6,100,110); // null
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question