I've been trying to solve this problem. I already read the editorial but it was too short for me to understand. Can anyone please explain how to solve this problem?
# | 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 | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 151 |
Name |
---|
Do binary search on X where X is the number of values in the matrix less than X. Thus initial low=1, high=n*m and then for every mid=(low+high)/2 calculate the number of values less than mid in the matrix and shift the low and high pointers accordingly.
To calculate the number of values less than mid in the matrix :-- num=0, then for each row i 1 to n: num+=min(m, (mid-1)/i)
I hope this gives you enough clarification of what to do! :)
Thanks :)
I kn
Have you tried reading this?
Didn't know about it :/
Hi!
I solved this problem quite recently. My algorithm matched the one in the editorial, here's my explanation.
First of all, brute force can't work, that would need O(n·m) time. So, that's out of question.
But we do know one thing, that the number of multiples of a number n strictly less than a value x are always equal to . It's not too tough to see the correctness of this, and can be proven using elementary math.
Using this observation, we can run a binary search for such number x such that the number of multiples of numbers 1 to n are equal to k. But because we only consider the first m multiples of these numbers(as the table doesn't have numbers greater than this), the number of values less than a number x in the multiplication table ultimately amount to
The above value can be calculated in O(n) time. The work left is implementing a binary search that searches the interval 1, 2, ... , 25·1010 as the maximum value of answer can be n·m. The final time complexity of solution amounts to O(n·log(n·m)).
I hope my explanation makes sense. Please point out any errors. My solution can be found at 13549897.
Thanks a lot :)