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 | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
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 .