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 | jiangly | 3976 |
2 | tourist | 3815 |
3 | jqdai0815 | 3682 |
4 | ksun48 | 3614 |
5 | orzdevinwang | 3526 |
6 | ecnerwala | 3514 |
7 | Benq | 3482 |
8 | hos.lyric | 3382 |
9 | gamegame | 3374 |
10 | heuristica | 3357 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | -is-this-fft- | 165 |
3 | Um_nik | 161 |
3 | atcoder_official | 161 |
5 | djm03178 | 157 |
6 | Dominater069 | 156 |
7 | adamant | 154 |
8 | luogu_official | 152 |
9 | awoo | 151 |
10 | TheScrasse | 147 |
Name |
---|
sieve[i]
gives you the index of the biggest prime factor. The index is one-based.sieve[20] == 3
, because20 = 2*2*5
andprimes[3] == 5
(5
is 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,
primes
is 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