Hi!
Did you know is O(nlogn)? (ω(n) is the number of distinct prime divisors of n)
I wonder why! Do you have any mathematical proof for this?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Hi!
Did you know is O(nlogn)? (ω(n) is the number of distinct prime divisors of n)
I wonder why! Do you have any mathematical proof for this?
Name |
---|
Because 2w(i) ≤ d(i) (d(n) is the number of divisors of n), so this is less than sum of d(i), which is the number of pairs i, j such that j divides i, which is sum of n/j, which is O(nlogn).
At the first look I was totally surprised about this fact, but it sounds easy when you say it like that!
Thanks!
it's nice information, do you know any problems that can be solved using it?
It's one of training tasks for our national OI (INOI):
Consider a n × n forest. For each relatively prime pair (i, j)i, j ≤ n, we plant a tree on position (i, j). The problem is to calculate total sum of pairwise distances between trees!
n ≤ 106, distance((a, b), (c, d)) = |a - c| + |b - d|
Also you can use that fact for this problem.
I don't think that much theoretically about problem, since each number lower than 10^6 has at most 7 distinct prime divisor, we can perform 2^7 * 10^6 :D This problem is much like SGU 370
Yes, but it's always good to know the exact complexity of our solution! (Without considering the limits)
What about lower bound? I can prove just Ω(nloglogn)
Lower bound:
Let Pn be a set of primes not larger than n.
(look here: http://en.wikipedia.org/wiki/Divergence_of_the_sum_of_the_reciprocals_of_the_primes). It follows that average number of different primes divisors is , so since 2x is convex we get that it's at least .