Skip to content

Commit 17290c5

Browse files
authored
Translated solution.md
1 parent 08f0076 commit 17290c5

File tree

1 file changed

+12
-12
lines changed
  • 1-js/02-first-steps/12-while-for/7-list-primes

1 file changed

+12
-12
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
There are many algorithms for this task.
1+
Yra daug algoritmų šiai užduočiai.
22

3-
Let's use a nested loop:
3+
Panaudokime matrioškinį ciklą:
44

55
```js
6-
For each i in the interval {
7-
check if i has a divisor from 1..i
8-
if yes => the value is not a prime
9-
if no => the value is a prime, show it
6+
Kiekvienam i intervale {
7+
patikrinkite ar i turi daliklį iš 1..i
8+
jeigu taip => vertė nėra pirminius skaičius
9+
jeigu ne => vertė yra pirminis skaičius, parodykite ją
1010
}
1111
```
1212

13-
The code using a label:
13+
Kodas naudojant etiketę:
1414

1515
```js run
1616
let n = 10;
1717

1818
nextPrime:
19-
for (let i = 2; i <= n; i++) { // for each i...
19+
for (let i = 2; i <= n; i++) { // kiekvienam i...
2020

21-
for (let j = 2; j < i; j++) { // look for a divisor..
22-
if (i % j == 0) continue nextPrime; // not a prime, go next i
21+
for (let j = 2; j < i; j++) { // ieškoti daliklio..
22+
if (i % j == 0) tęsti nextPrime; // ne pirminis skaičius, eiti prie sekančio i
2323
}
2424

25-
alert( i ); // a prime
25+
alert( i ); // pirminis
2626
}
2727
```
2828

29-
There's a lot of space to optimize it. For instance, we could look for the divisors from `2` to square root of `i`. But anyway, if we want to be really efficient for large intervals, we need to change the approach and rely on advanced maths and complex algorithms like [Quadratic sieve](https://en.wikipedia.org/wiki/Quadratic_sieve), [General number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve) etc.
29+
Yra daug vietos, kur galima jį optimizuoti. Pavyzdžiui, galėtume ieškoti daliklių nuo `2` iki `i` šaknies. Bet kokiu atveju, jeigu norime būti efektyvūs dideliems intervalams, reikia pakeisti priėjimo būdus ir pasitikėti pažengusia matematika ir sudėtingais algoritmais kaip [Quadratic sieve](https://en.wikipedia.org/wiki/Quadratic_sieve), [General number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve) etc.

0 commit comments

Comments
 (0)