Hi!
I've come across this piece of code of a (modified?) sieve and I'm trying to figure out what sieve[i] means and how it works, specially the 2nd for.
Would you help me, please?
Thanks!
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | jiangly | 3631 |
| 4 | Kevin114514 | 3574 |
| 5 | maroonrk | 3521 |
| 6 | strapple | 3515 |
| 7 | Radewoosh | 3461 |
| 8 | tourist | 3428 |
| 9 | turmax | 3378 |
| 10 | Um_nik | 3376 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 140 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
| Name |
|---|



sieve[i]gives you the index of the biggest prime factor. The index is one-based.sieve[20] == 3, because20 = 2*2*5andprimes[3] == 5(5is the third prime number)Using this method, you generate the prime factorization pretty quick. You can find the biggest prime number using the
sieve, divide by this number and repeat with the result.I think you meant
prime[5] = 3, right?No,
primesis a list of primes.primes = { 0, 2, 3, 5, 7, 11, ... }Ah, sorry I totally misunderstood.
I thought you meant to give another example, which is
sieve[5] = 3, and didn't notice the difference in arrays' names. Sorry about that :D